Skip to content

Commit

Permalink
couple more bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sky-is-winning committed Aug 5, 2024
1 parent d80af71 commit cc9d39f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/generate-page-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export default class GeneratePageData {

let truePageName = page.slice(1)
let pageName = truePageName.replaceAll("_", " ");
this.templateGenerator.setPageName(pageName);
for (const replacer of REPLACERS) {
pageName = pageName.replaceAll(replacer[1], replacer[0]);
}
Expand Down Expand Up @@ -232,15 +233,15 @@ function hideNav() {
line = line.trim();
if (inTable) {
tableLines += `\n${line}`;
if (line == "|}") {
if (line.endsWith("|}")) {
inTable = false;
let wikitable = await this.templateGenerator.generateWikitable(tableLines);
content += wikitable;
tableLines = "";
}
} else if (inTemplate) {
templateLines += `\n${line}`;
if (line == "}}") {
if (line.endsWith("}}")) {
inTemplate = false;
let template = await this.templateGenerator.generateTemplate(templateLines);
content += template;
Expand Down
16 changes: 14 additions & 2 deletions src/generate-template.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@ export default class GenerateTemplate {
this.webserver = wikiParser.webserver;
}

generateAmbox(wt) {
setPageName(pageName) {
this.pageName = pageName;
}

getPageName() {
return this.pageName;
}

async generateAmbox(wt) {
let boxContent = this.extractTemplate(wt, "Ambox")[0];

// Use a regex to split the content into key-value pairs
Expand All @@ -26,7 +34,7 @@ export default class GenerateTemplate {
let ambox = `<table class="metadata plainlinks ambox ambox-${boxData.type}" style="">`;
ambox += `<tbody><tr>`;
ambox += `<td class="mbox-image><div style="width:${boxData.image.size}"><span typeof="mw:File"><span><img src="${boxData.image.address}" width="${boxData.image.size}" height="auto" class="mw-file-element"/></span></span></span></div></td>`;
ambox += `<td class="mbox-text" style="">${boxData.text}</td>`;
ambox += `<td class="mbox-text" style="">${await this.parseLine(boxData.text)}</td>`;
ambox += `</tr></tbody></table>`;
return ambox;
}
Expand Down Expand Up @@ -336,6 +344,10 @@ export default class GenerateTemplate {
async generateTemplate(template, bypassNoInclude = false) {
template = template.replaceAll("n/a", "NA");

if (template === "BASEPAGENAME") {
return this.getPageName();
}

let templateName = template.split("|")[0];
const templateData = template.split("|").slice(1);

Expand Down

0 comments on commit cc9d39f

Please sign in to comment.