Skip to content

Commit

Permalink
fix: return all matches not just the first
Browse files Browse the repository at this point in the history
  • Loading branch information
dominique-pfister committed Apr 6, 2024
1 parent 55e28fe commit 8c01b77
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/helix-shared-indexer/src/index-resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,10 @@ const helpers = {
// eslint-disable-next-line no-param-reassign
elements = [elements];
}
let previousIndex = -1;
elements.forEach((el) => {
let m;
let previousIndex = -1;

const content = typeof el === 'string' ? el : toText(el);

// eslint-disable-next-line no-cond-assign
Expand Down
11 changes: 11 additions & 0 deletions packages/helix-shared-indexer/test/index-resource.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ indices:
select: main > div:last-of-type > p:nth-of-type(3)
value: |
match(innerHTML(el), '(.*?)<br><br>.*|(.*)')
all-matches:
select: a
values: |
match(attribute(el, 'href'), 'https://[^/]+/assets/.*')
`;

const BODY = `
Expand Down Expand Up @@ -160,6 +164,9 @@ const BODY = `
<p>before<br><br>after</p>
<p>before<br>after</p>
</div>
<a href="https://my.domain.com/assets/asset-link">an asset</a>
<a href="https://my.domain.com">some link</a>
<a href="https://my.domain.com/assets/asset-link2">another asset</a>
</main>
<footer></footer>
</body>
Expand All @@ -171,6 +178,10 @@ describe('Index Resource Tests', () => {
const headers = new Headers({ 'last-modified': 'Mon, 22 Feb 2021 15:28:00 GMT' });
const record = indexResource('/abc/de/ab/fg/abcd', { body: BODY, headers }, config.indices[0], console);
assert.deepEqual(record, {
'all-matches': [
'https://my.domain.com/assets/asset-link',
'https://my.domain.com/assets/asset-link2',
],
author: 'Max',
'bad-selector': '',
'call-unknown-function': '',
Expand Down

0 comments on commit 8c01b77

Please sign in to comment.