embed ejs templates
This commit is contained in:
parent
15f779e63f
commit
7f4773c276
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "jam-my-stack",
|
"name": "jam-my-stack",
|
||||||
"version": "1.0.10",
|
"version": "1.0.11",
|
||||||
"repository": {
|
"repository": {
|
||||||
"url": "https://github.com/wgroeneveld/jam-my-stack",
|
"url": "https://github.com/wgroeneveld/jam-my-stack",
|
||||||
"type": "git"
|
"type": "git"
|
||||||
|
|
|
@ -1,9 +1,13 @@
|
||||||
const ejs = require('ejs');
|
const ejs = require('ejs');
|
||||||
|
const templates = require('./templates');
|
||||||
|
|
||||||
const got = require("got");
|
const got = require("got");
|
||||||
const parser = require("fast-xml-parser");
|
const parser = require("fast-xml-parser");
|
||||||
const { readFileSync, writeFileSync, existsSync, mkdirSync } = require('fs');
|
|
||||||
const ent = require('ent');
|
const ent = require('ent');
|
||||||
|
|
||||||
|
const { writeFileSync, existsSync, mkdirSync } = require('fs');
|
||||||
const { getFiles } = require('./../file-utils');
|
const { getFiles } = require('./../file-utils');
|
||||||
|
|
||||||
const dayjs = require('dayjs');
|
const dayjs = require('dayjs');
|
||||||
const utc = require('dayjs/plugin/utc');
|
const utc = require('dayjs/plugin/utc');
|
||||||
dayjs.extend(utc);
|
dayjs.extend(utc);
|
||||||
|
@ -17,29 +21,15 @@ function stripBeforeLastSlash(str) {
|
||||||
return str.substring(str.lastIndexOf('/') + 1, str.length)
|
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) {
|
function convertAtomItemToMd(item, notesdir) {
|
||||||
const path = `${notesdir}/${item.year}/${item.month}`
|
const path = `${notesdir}/${item.year}/${item.month}`
|
||||||
if(!existsSync(`${notesdir}/${item.year}`)) mkdirSync(`${notesdir}/${item.year}`)
|
if(!existsSync(`${notesdir}/${item.year}`)) mkdirSync(`${notesdir}/${item.year}`)
|
||||||
if(!existsSync(path)) mkdirSync(path)
|
if(!existsSync(path)) mkdirSync(path)
|
||||||
|
|
||||||
let mddata = `---
|
let mddata = ejs.render(templates.markdown, { item })
|
||||||
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}
|
|
||||||
`
|
|
||||||
if(item.media.length > 0) {
|
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')
|
writeFileSync(`${path}/${item.hash}.md`, mddata, 'utf-8')
|
||||||
|
|
|
@ -1,9 +0,0 @@
|
||||||
<div class="flex">
|
|
||||||
<% images.forEach(function(image){ %>
|
|
||||||
<div>
|
|
||||||
<a class="lbox" href="<%= image %>">
|
|
||||||
<img src="<%= image %>" alt="Enclosed Toot image">
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
<% }); %>
|
|
||||||
</div>
|
|
|
@ -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 = `
|
||||||
|
<div class="flex">
|
||||||
|
<% images.forEach(function(image){ %>
|
||||||
|
<div>
|
||||||
|
<a class="lbox" href="<%- image %>">
|
||||||
|
<img loading="lazy" src="<%- image %>" alt="Enclosed Toot image">
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<% }); %>
|
||||||
|
</div>
|
||||||
|
`
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
markdown,
|
||||||
|
enclosures
|
||||||
|
}
|
|
@ -26,13 +26,13 @@ Enjoyed an afternoon of oldskool Diablo II on the Europebattle servers. We did a
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<a class=\\"lbox\\" href=\\"https://chat.brainbaking.com/media/6f8b72ca-9bfb-460b-9609-c4298a8cab2b/EuropeBattle%202021-03-14%2016-20-36-87.jpg\\">
|
<a class=\\"lbox\\" href=\\"https://chat.brainbaking.com/media/6f8b72ca-9bfb-460b-9609-c4298a8cab2b/EuropeBattle%202021-03-14%2016-20-36-87.jpg\\">
|
||||||
<img src=\\"https://chat.brainbaking.com/media/6f8b72ca-9bfb-460b-9609-c4298a8cab2b/EuropeBattle%202021-03-14%2016-20-36-87.jpg\\" alt=\\"Enclosed Toot image\\">
|
<img loading=\\"lazy\\" src=\\"https://chat.brainbaking.com/media/6f8b72ca-9bfb-460b-9609-c4298a8cab2b/EuropeBattle%202021-03-14%2016-20-36-87.jpg\\" alt=\\"Enclosed Toot image\\">
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<a class=\\"lbox\\" href=\\"https://chat.brainbaking.com/media/3dbcb044-2acc-4ace-a4f6-37ce94c3f2b1/EuropeBattle%202021-03-14%2015-35-01-56.jpg\\">
|
<a class=\\"lbox\\" href=\\"https://chat.brainbaking.com/media/3dbcb044-2acc-4ace-a4f6-37ce94c3f2b1/EuropeBattle%202021-03-14%2015-35-01-56.jpg\\">
|
||||||
<img src=\\"https://chat.brainbaking.com/media/3dbcb044-2acc-4ace-a4f6-37ce94c3f2b1/EuropeBattle%202021-03-14%2015-35-01-56.jpg\\" alt=\\"Enclosed Toot image\\">
|
<img loading=\\"lazy\\" src=\\"https://chat.brainbaking.com/media/3dbcb044-2acc-4ace-a4f6-37ce94c3f2b1/EuropeBattle%202021-03-14%2015-35-01-56.jpg\\" alt=\\"Enclosed Toot image\\">
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue