diff --git a/package.json b/package.json index 9e2ec69..429b4d3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jam-my-stack", - "version": "1.0.10", + "version": "1.0.11", "repository": { "url": "https://github.com/wgroeneveld/jam-my-stack", "type": "git" diff --git a/src/mastodon/feed-parser.js b/src/mastodon/feed-parser.js index 70b0deb..21aaa9a 100644 --- a/src/mastodon/feed-parser.js +++ b/src/mastodon/feed-parser.js @@ -1,9 +1,13 @@ const ejs = require('ejs'); +const templates = require('./templates'); + const got = require("got"); const parser = require("fast-xml-parser"); -const { readFileSync, writeFileSync, existsSync, mkdirSync } = require('fs'); const ent = require('ent'); + +const { writeFileSync, existsSync, mkdirSync } = require('fs'); const { getFiles } = require('./../file-utils'); + const dayjs = require('dayjs'); const utc = require('dayjs/plugin/utc'); dayjs.extend(utc); @@ -17,29 +21,15 @@ function stripBeforeLastSlash(str) { return str.substring(str.lastIndexOf('/') + 1, str.length) } -function tmpl(filename, data) { - const template = readFileSync(filename).toString() - return ejs.render(template, data, { - rmWhitespace: true - }) -} - function convertAtomItemToMd(item, notesdir) { const path = `${notesdir}/${item.year}/${item.month}` if(!existsSync(`${notesdir}/${item.year}`)) mkdirSync(`${notesdir}/${item.year}`) if(!existsSync(path)) mkdirSync(path) - let mddata = `--- -source: "${item.url}" -context: "${item.context}" -title: "${item.title}" -date: "${item.year}-${item.month}-${item.day}T${item.date.format("HH:mm:ss")}" ---- + let mddata = ejs.render(templates.markdown, { item }) -${item.content} -` if(item.media.length > 0) { - mddata += '\n' + tmpl('./src/mastodon/render-enclosures.ejs', { images: item.media }) + mddata += '\n' + ejs.render(templates.enclosures, { images: item.media }, { rmWhitespace: true }) } writeFileSync(`${path}/${item.hash}.md`, mddata, 'utf-8') diff --git a/src/mastodon/render-enclosures.ejs b/src/mastodon/render-enclosures.ejs deleted file mode 100644 index 6a3c4b6..0000000 --- a/src/mastodon/render-enclosures.ejs +++ /dev/null @@ -1,9 +0,0 @@ -
- <% images.forEach(function(image){ %> -
- - Enclosed Toot image - -
- <% }); %> -
diff --git a/src/mastodon/templates.js b/src/mastodon/templates.js new file mode 100644 index 0000000..c695112 --- /dev/null +++ b/src/mastodon/templates.js @@ -0,0 +1,27 @@ + +const markdown = `--- +source: "<%- item.url %>" +context: "<%- item.context %>" +title: "<%- item.title %>" +date: "<%- item.year %>-<%- item.month %>-<%- item.day %>T<%- item.date.format('HH:mm:ss') %>" +--- + +<%- item.content %> +` + +const enclosures = ` +
+ <% images.forEach(function(image){ %> +
+ + Enclosed Toot image + +
+ <% }); %> +
+` + +module.exports = { + markdown, + enclosures +} diff --git a/test/mastodon/__snapshots__/feed-parser.test.js.snap b/test/mastodon/__snapshots__/feed-parser.test.js.snap index d57d26b..0886f38 100644 --- a/test/mastodon/__snapshots__/feed-parser.test.js.snap +++ b/test/mastodon/__snapshots__/feed-parser.test.js.snap @@ -26,13 +26,13 @@ Enjoyed an afternoon of oldskool Diablo II on the Europebattle servers. We did a
-\\"Enclosed +\\"Enclosed
-\\"Enclosed +\\"Enclosed