Skip to content

Commit

Permalink
fix slots in title
Browse files Browse the repository at this point in the history
  • Loading branch information
giuseppeg committed Nov 18, 2020
1 parent 1b27fc1 commit d5ce205
Show file tree
Hide file tree
Showing 6 changed files with 679 additions and 144 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ args.push("--posthtml-md2html.gfm");
args.push("true");

if (fs.existsSync(outDir)) {
fs.rmdirSync(outDir, { recursive: true });
fs.rmSync(outDir, { recursive: true, force: true });
}

const htmlOnlyIndex = args.findIndex((a) => a === "-x" || a === "--htmlOnly");
Expand Down
15 changes: 15 additions & 0 deletions lib/posthtml-xm-import/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module.exports = (options = {}) => {
? !!options.strict
: true;

enableSlotsInTitle(tree);
tree = handleImportNodes(tree, options, tree.messages);

tree.markdownNodes.forEach(([importNode, markdownTree]) => {
Expand Down Expand Up @@ -87,6 +88,7 @@ function handleImportNodes(tree, options, messages) {
options,
messages
);
enableSlotsInTitle(importedTree);
const slotNodes = select(importedTree, ["slot"]);
const fillNodes = select(importNode.content, ["fill"]);
fillNodes[UNNAMED] = importNode;
Expand Down Expand Up @@ -229,6 +231,19 @@ function select(content = [], tags) {
return nodes;
}

function enableSlotsInTitle(tree) {
match.call(tree, { tag: "title" }, (node) => {
if (
node.content &&
typeof node.content[0] === "string" &&
node.content[0].includes("</slot")
) {
node.content[0] = parseToPostHtml(node.content[0])[0];
}
return node;
});
}

function getError() {
const message = util.format.apply(util, arguments);
return new Error("[xm-import] " + message);
Expand Down
4 changes: 2 additions & 2 deletions lib/posthtml-xm-import/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"author": "Giuseppe Gurgone",
"license": "MIT",
"peerDependencies": {
"posthtml": "^0.13.1",
"posthtml-parser": "^0.4.2"
"posthtml": "^0.14.0",
"posthtml-parser": "^0.6.0"
}
}
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"dependencies": {
"front-matter": "^4.0.2",
"ncp": "^2.0.0",
"posthtml-cli": "^0.7.5",
"posthtml-cli": "^0.8.1",
"posthtml-md2html": "^0.0.2",
"posthtml-xm-import": "^0.1.1",
"sirv": "^1.0.6"
Expand All @@ -36,5 +36,8 @@
"highlight.js": "^10.1.2",
"snapshot-dir": "^1.1.2",
"source-map-support": "^0.5.19"
},
"resolutions": {
"posthtml": "0.14.0"
}
}
6 changes: 2 additions & 4 deletions test/snapshot.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,5 @@
"nested/nested/nested/_nested.html": "16fa3661c54cf0d822406e6d79683fe0",
"nested/nested/nested/page.html": "cbdf34c25e3969fec4653249d1fcc919",
"simple/_base.html": "305317b853a0c126acf2e88eb5d15e20",
"simple/index.html": "ee61e485389c4f5e4de7c67a52f8dbd1",
"template/_base.html": "6545b9cca12a58354ad3e4b1d8589e58",
"template/index.html": "1892438182eaaf8541d303c7e826054a"
}
"simple/index.html": "ee61e485389c4f5e4de7c67a52f8dbd1"
}
Loading

0 comments on commit d5ce205

Please sign in to comment.