Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
awxiaoxian2020 committed Oct 11, 2023
1 parent 03e2c5d commit e89d610
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
4 changes: 1 addition & 3 deletions src/utilities/list2Tree/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@ function list2Tree(parent, anchors, topLevel = findTopLevel(anchors)) {
children: list2Tree(hd.title, others, findTopLevel(others)),
};
} else {
const match = /^.+(\s*\$#([a-z0-9\-_]+?)\$\s*)$/.exec(parent);
const newParent = match ? parent.replace(match[1], '').trim() : parent;
return {
...c[0],
title2: c[0].title.replace(new RegExp(`^${newParent}\\.`, 'i'), ''),
title2: c[0].title.replace(new RegExp(`^${parent}\\.`, 'i'), ''),
};
}
});
Expand Down
3 changes: 2 additions & 1 deletion src/utilities/process-readme.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function linkFixerFactory(sourceUrl) {
console.log('REWRITE URL:', oldHref, '-->', href);
}

return markdownLink.replace(oldHref, href);
return markdownLink.replaceAll(oldHref, href);
};
}

Expand Down Expand Up @@ -105,6 +105,7 @@ export default function processREADME(body, options = {}) {
// EXAMPLE: [Contributing](./.github/CONTRIBUTING.md)
// EXAMPLE: [Contributing](CONTRIBUTING.md)
// EXAMPLE: [line-identifier]: https://webpack.js.org/loaders/
// EXAMPLE: [`./src/config.d.ts`](./src/config.d.ts)
.replace(inlineLinkRegex, linkFixerFactory(options.source))
// Replace any <h2> with `##`
.replace(/<h2[^>]*>/g, '## ')
Expand Down
11 changes: 11 additions & 0 deletions src/utilities/process-readme.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,15 @@ describe('processReadme', () => {
'- [html-webpack-plugin](https://github.com/jantimon/html-webpack-plugin)'
);
});
it('rewrite relative url', () => {
const options = {
source:
'https://raw.githubusercontent.com/webpack-contrib/postcss-loader/master/README.md',
};
const loaderMDData =
'See the file [`./src/config.d.ts`](./src/config.d.ts).';
expect(processReadme(loaderMDData, options)).toEqual(
'See the file [`https://github.com/webpack-contrib/postcss-loader/blob/master/src/config.d.ts`](https://github.com/webpack-contrib/postcss-loader/blob/master/src/config.d.ts).'
);
});
});
11 changes: 10 additions & 1 deletion src/utilities/yaml-headmatter.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@ export default function yamlHeadmatter(fields) {
let ret = '---\n';

Object.keys(fields).map((field) => {
ret += `${field}: ${fields[field]}\n`;
if (field === 'contributors') {
if(fields[field].length) {
ret += `${field}:\n`;
fields[field].forEach((contributor) => {
ret += ` - ${contributor}\n`;
});
}
} else {
ret += `${field}: ${fields[field]}\n`;
}
});

ret = `${ret}---\n`;
Expand Down

0 comments on commit e89d610

Please sign in to comment.