aboutsummaryrefslogtreecommitdiffstats
path: root/app/wikiparser.mjs
diff options
context:
space:
mode:
authorLMBishop <13875753+LMBishop@users.noreply.github.com>2021-12-21 22:40:00 +0000
committerLMBishop <13875753+LMBishop@users.noreply.github.com>2021-12-21 22:40:00 +0000
commit26df7ae8845ed3c2fe47456a7eff76ecb6d89e5e (patch)
treee211995557d901fcc7b7b7647448030ae29f393d /app/wikiparser.mjs
parent9250be8a1b0b5a6478130a0fd6a832754ac863b0 (diff)
Fix transclusion for templates
Diffstat (limited to 'app/wikiparser.mjs')
-rw-r--r--app/wikiparser.mjs15
1 files changed, 6 insertions, 9 deletions
diff --git a/app/wikiparser.mjs b/app/wikiparser.mjs
index a74b216..519100b 100644
--- a/app/wikiparser.mjs
+++ b/app/wikiparser.mjs
@@ -29,7 +29,7 @@ const re = (regex, flag = 'mgi') => {
const r = String.raw;
const arg = r`\s*([^|}]+?)\s*`;
-export function parse(data) {
+export function parse(directory, data) {
const vars = {};
const metadata = {};
let nowikis = [];
@@ -117,19 +117,16 @@ export function parse(data) {
// Templates: {{template}}
.replace(re(r`{{ \s* ([^#}|]+?) (\|[^}]+)? }} (?!})`), (_, title, params = '') => {
if (/{{/.test(params)) return _;
- const page = 'Template:' + title.trim().replace(/ /g, '_');
+ const page = title.includes(':') ? title : `Template:${title}`
// Retrieve template content
- let content = '';
- try {
- content = fs.readFileSync(page + '.wiki', 'utf8' );
- }
- catch {
- return `<a class="internal-link redlink" title="${title}" href="${page}">${title}</a>`;
+ let content = directory.get(page);
+ if (!content) {
+ return `<a class="internal-link redlink" title="${title}" href="${page}">Template:${title}</a>`;
}
// Remove non-template sections
- content = content
+ content = content.raw
.replace(/<noinclude>.*?<\/noinclude>/gs, '')
.replace(/.*<(includeonly|onlyinclude)>|<\/(includeonly|onlyinclude)>.*/gs, '');