Skip to content

MarkdownPreview

Created: 2020-02-15 11:50:14 -0800 Modified: 2020-03-21 16:41:51 -0700

  • This is the extension that I use for Sublime to generate HTML from Markdown.
  • If you try exporting while you have text selected, it will only export the selected text.

Adding meta tags (like favicon stuff)

Section titled Adding meta tags (like favicon stuff)

I just wrote a quick program to do this for me in Node so that I wouldn’t have to modify the extension (I’m really in a ProblemA situation as I write this note).

const fs = require("fs");
const fileName = "./faq.html";
function replaceMetaTags(allHtmlContent) {
const headTag = "<head>";
const allMetaTags = `
<link rel="apple-touch-icon" sizes="180x180" href="/favicons/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/favicons/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicons/favicon-16x16.png">
<link rel="manifest" href="/favicons/site.webmanifest">
<link rel="mask-icon" href="/favicons/safari-pinned-tab.svg" color="#5bbad5">
<link rel="shortcut icon" href="/favicons/favicon.ico"></link>
`;
const newContents = allHtmlContent.replace(
headTag,
`${headTag}${allMetaTags}`
);
return newContents;
}
try {
console.log(`Reading from ${fileName}`);
const data = fs.readFileSync(fileName, "utf8");
if (data.indexOf("apple-touch-icon") === -1) {
const newContents = replaceMetaTags(data);
fs.writeFileSync(fileName, newContents);
console.log("Successfully added meta tags.");
} else {
console.log("You already ran this once; no need to run it again.");
}
} catch (err) {
console.error("Error", err);
}