Skip to content

Commit 854f5c9

Browse files
committed
Re-fix template links
1 parent 0bb915b commit 854f5c9

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/parse.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ function toLinkText(link: string) {
1414
return cleanedLink[0].toUpperCase() + cleanedLink.slice(1);
1515
}
1616

17+
function toFileText(link: string) {
18+
const cleanedLink = link.trim().replace(/ /g, '_');
19+
return cleanedLink[0].toUpperCase() + cleanedLink.slice(1);
20+
}
21+
1722
function parseDimensions(dimStr: string) {
1823
const regex = /(\d*)(?:x(\d*))?px/;
1924
const match = dimStr.match(regex);
@@ -267,12 +272,12 @@ export function parse(data: string, config: Config = {}): Result {
267272
.replace(re(r`(?<!{) {{ \s* ([^#{}|]+?) \s* (\|[^{}]+)? }} (?!})`), (_, title, params = '') => {
268273
if (params.includes('{{')) return _;
269274

270-
const templateFile = title.trim().replace(/ /g, '_');
275+
const templateFile = toFileText(title);
271276
const page: string = paths.join(templatesFolder, templateFile);
272277
let content = '';
273278
// Try retrieve template content
274279
try {
275-
content = fs.readFileSync(toLinkText(page) + '.wiki', { encoding: 'utf8' })
280+
content = fs.readFileSync(page + '.wiki', { encoding: 'utf8' })
276281
}
277282
catch {
278283
// Return redlink if template doesn't exist

0 commit comments

Comments
 (0)