-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use parser to render about page content
- Loading branch information
Showing
10 changed files
with
304 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,5 @@ | ||
{% extends "layouts/base.njk" %} | ||
|
||
{% block content %} | ||
{% for key, value in sections %} | ||
<section> | ||
<h2>{{ key }}</h2> | ||
<p>{{ value }}</p> | ||
</section> | ||
{% endfor %} | ||
{{ content | safe }} | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
{% uioScripts %} | ||
<script type="text/javascript" src="/assets/scripts/app.js" defer></script> | ||
{% if page.fileSlug === "about" %} | ||
<script type="text/javascript" src="/assets/scripts/parse.js" defer></script> | ||
{% endif %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { parseHTML } from "linkedom"; | ||
|
||
export default (value, outputPath) => { | ||
if (outputPath && outputPath.includes(".html")) { | ||
const { document } = parseHTML(value); | ||
if (document) { | ||
const main = document.getElementsByTagName("main"); | ||
const updatedMain = document.createElement("main"); | ||
let section = document.createElement("section"); | ||
|
||
if (main[0]?.children) { | ||
for (const element of main[0].children) { | ||
if (element.tagName === "H2" && element.classList?.length === 0) { | ||
if (section.children.length > 0) { | ||
updatedMain.append(section); | ||
section = document.createElement("section"); | ||
} | ||
section.append(element); | ||
} else if (element.tagName === "P" && element.classList?.length === 0) { | ||
section.append(element); | ||
} else { | ||
if (section.children.length > 0) { | ||
updatedMain.append(section); | ||
} | ||
updatedMain.append(element); | ||
} | ||
} | ||
main[0].replaceWith(updatedMain); | ||
} | ||
|
||
return "<!DOCTYPE html>\r\n" + document.documentElement?.outerHTML; | ||
} | ||
} | ||
|
||
return value; | ||
}; |
Oops, something went wrong.