This commit is contained in:
Yarmo Mackenbach 2020-09-25 14:59:04 +02:00
parent 060daae416
commit a284995ee8
8 changed files with 146 additions and 101 deletions

25
package-lock.json generated
View File

@ -150,6 +150,16 @@
"integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=",
"dev": true "dev": true
}, },
"bent": {
"version": "7.3.10",
"resolved": "https://registry.npmjs.org/bent/-/bent-7.3.10.tgz",
"integrity": "sha512-X2P2nGRWejGn6IjJfL4usOuAVMng1DdyuRhXLGOcUvEblBcLZenrSjlkgS8ob1s3tbq3mo1FDxKhCRNvcf0y0Q==",
"requires": {
"bytesish": "^0.4.1",
"caseless": "~0.12.0",
"is-stream": "^2.0.0"
}
},
"binary-extensions": { "binary-extensions": {
"version": "2.1.0", "version": "2.1.0",
"resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.1.0.tgz", "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.1.0.tgz",
@ -213,6 +223,11 @@
"resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.0.tgz", "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.0.tgz",
"integrity": "sha512-zauLjrfCG+xvoyaqLoV8bLVXXNGC4JqlxFCutSDWA6fJrTo2ZuvLYTqZ7aHBLZSMOopbzwv8f+wZcVzfVTI2Dg==" "integrity": "sha512-zauLjrfCG+xvoyaqLoV8bLVXXNGC4JqlxFCutSDWA6fJrTo2ZuvLYTqZ7aHBLZSMOopbzwv8f+wZcVzfVTI2Dg=="
}, },
"bytesish": {
"version": "0.4.3",
"resolved": "https://registry.npmjs.org/bytesish/-/bytesish-0.4.3.tgz",
"integrity": "sha512-OuwahLpcvvYfFnxZL0E/Gx6D7U2A72JM8cXL+5uiiZP/x84B/arG5kL8QfRLCLKb/Ttp1Jk2bPDLeltP96dtbw=="
},
"cacheable-request": { "cacheable-request": {
"version": "6.1.0", "version": "6.1.0",
"resolved": "https://registry.npmjs.org/cacheable-request/-/cacheable-request-6.1.0.tgz", "resolved": "https://registry.npmjs.org/cacheable-request/-/cacheable-request-6.1.0.tgz",
@ -251,6 +266,11 @@
"integrity": "sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==", "integrity": "sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==",
"dev": true "dev": true
}, },
"caseless": {
"version": "0.12.0",
"resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz",
"integrity": "sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw="
},
"chalk": { "chalk": {
"version": "3.0.0", "version": "3.0.0",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-3.0.0.tgz", "resolved": "https://registry.npmjs.org/chalk/-/chalk-3.0.0.tgz",
@ -834,6 +854,11 @@
"has-symbols": "^1.0.1" "has-symbols": "^1.0.1"
} }
}, },
"is-stream": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/is-stream/-/is-stream-2.0.0.tgz",
"integrity": "sha512-XCoy+WlUr7d1+Z8GgSuXmpuUFC9fOhRXglJMx+dwLKTkL44Cjd4W1Z5P+BQZpr+cR93aGP4S/s7Ftw6Nd/kiEw=="
},
"is-typedarray": { "is-typedarray": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz", "resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz",

View File

@ -15,6 +15,7 @@
"author": "Yarmo Mackenbach <yarmo@yarmo.eu> (https://yarmo.eu)", "author": "Yarmo Mackenbach <yarmo@yarmo.eu> (https://yarmo.eu)",
"license": "AGPL-3.0-or-later", "license": "AGPL-3.0-or-later",
"dependencies": { "dependencies": {
"bent": "^7.3.10",
"dotenv": "^8.2.0", "dotenv": "^8.2.0",
"express": "^4.17.1", "express": "^4.17.1",
"express-validator": "^6.6.1", "express-validator": "^6.6.1",

View File

@ -4,24 +4,7 @@ const _ = require('lodash')
const mw = require('../server/middlewares') const mw = require('../server/middlewares')
const util = require('../server/util') const util = require('../server/util')
router.param('slug', async (req, res, next, slug) => { router.param('slug', mw.getPostBySlug)
let posts = await util.getBlogPosts()
posts = _.filter(posts, (p) => { return slug == p.slug })
if (posts.length > 0) {
res.locals.post = posts[0]
next()
return
}
posts = await util.getNotes()
posts = _.filter(posts, (p) => { return slug == p.slug })
if (posts.length > 0) {
res.locals.post = posts[0]
next()
return
}
res.locals.post = null
next()
})
router.get('/', mw.getBlogPosts, (req, res) => { router.get('/', mw.getBlogPosts, (req, res) => {
res.render('blog', { title: 'Blog — yarmo.eu' }) res.render('blog', { title: 'Blog — yarmo.eu' })
@ -29,9 +12,15 @@ router.get('/', mw.getBlogPosts, (req, res) => {
router.get('/blog', mw.getBlogPosts, (req, res) => { router.get('/blog', mw.getBlogPosts, (req, res) => {
res.render('blog', { title: 'Blog — yarmo.eu' }) res.render('blog', { title: 'Blog — yarmo.eu' })
}) })
router.get('/blog/:s', (req, res) => {
res.redirect(`/post/${req.params.s}`)
})
router.get('/notes', mw.getNotes, (req, res) => { router.get('/notes', mw.getNotes, (req, res) => {
res.render('notes', { title: 'Notes — yarmo.eu' }) res.render('notes', { title: 'Notes — yarmo.eu' })
}) })
router.get('/notes/:s', (req, res) => {
res.redirect(`/post/${req.params.s}`)
})
router.get('/post/:slug', (req, res) => { router.get('/post/:slug', (req, res) => {
res.render('post', { title: `${res.locals.post.title} — yarmo.eu` }) res.render('post', { title: `${res.locals.post.title} — yarmo.eu` })
}) })

View File

@ -13,6 +13,18 @@ module.exports.getNotes = async (req, res, next) => {
next() next()
} }
module.exports.getPostBySlug = async (req, res, next, slug) => {
let post = await util.getPost(slug)
if (post) {
post.webmentions = await util.getWebmentions(post.url)
post.hasWebmentions = post.webmentions.length > 0
}
res.locals.post = post
next()
}
module.exports.getVinyl = async (req, res, next) => { module.exports.getVinyl = async (req, res, next) => {
const file = fs.readFileSync(path.join(__dirname, '../', 'content', 'music', 'vinyl.yaml'), 'utf8') const file = fs.readFileSync(path.join(__dirname, '../', 'content', 'music', 'vinyl.yaml'), 'utf8')
res.locals.vinyl = YAML.parse(file) res.locals.vinyl = YAML.parse(file)

View File

@ -2,6 +2,8 @@ const fs = require('fs')
const { readdir } = require('fs').promises const { readdir } = require('fs').promises
const path = require('path') const path = require('path')
const { resolve } = require('path') const { resolve } = require('path')
const bent = require('bent')
const getJSON = bent('json')
const _ = require('lodash') const _ = require('lodash')
const md = require('markdown-it')({ typographer: true }) const md = require('markdown-it')({ typographer: true })
const yamlFront = require('yaml-front-matter') const yamlFront = require('yaml-front-matter')
@ -76,6 +78,27 @@ const getNotes = async (opts) => {
return data.reverse() return data.reverse()
} }
const getPost = async (slug) => {
let post = null, posts = await getBlogPosts()
posts = _.filter(posts, (p) => { return slug == p.slug })
post = posts.length > 0 ? posts[0] : null
if (!post) {
posts = await getNotes()
posts = _.filter(posts, (p) => { return slug == p.slug })
post = posts.length > 0 ? posts[0] : null
}
return post
}
const getWebmentions = async (url) => {
const data_1 = await getJSON(`https://webm.yarmo.eu/get?target=${url}`)
const data_2 = await getJSON(`https://webm.yarmo.eu/get?target=${url.replace('/post/', '/blog/')}`)
const data_3 = await getJSON(`https://webm.yarmo.eu/get?target=${url.replace('/post/', '/notes/')}`)
return data_1.concat(data_2).concat(data_3)
}
const getRSS = async (opts) => { const getRSS = async (opts) => {
if (!opts) { opts = {} } if (!opts) { opts = {} }
opts.include = 'include' in opts ? opts.include : ['blog', 'notes'] opts.include = 'include' in opts ? opts.include : ['blog', 'notes']
@ -141,5 +164,7 @@ module.exports = {
getFiles: getFiles, getFiles: getFiles,
getBlogPosts: getBlogPosts, getBlogPosts: getBlogPosts,
getNotes: getNotes, getNotes: getNotes,
getPost: getPost,
getWebmentions: getWebmentions,
getRSS: getRSS getRSS: getRSS
} }

View File

@ -1,38 +1,38 @@
extends templates/main extends templates/main
mixin webmention(item) mixin webmention(item)
if (!array_key_exists('type', item)) if (!('type' in item))
p p
if (array_key_exists('title', item)) if ('title' in item)
a(href="{item['source']}") !{item['title']} a(href=item.source) !{item.title}
else else
a(href="{item['source']}") !{item['source']} a(href=item.source) !{item.source}
if (array_key_exists('author_name', item)) if ('author_name' in item)
| by !{item['author_name']} | by !{item.author_name}
if (array_key_exists('date', item)) if ('date' in item)
| on !{item['date']} | on !{item.date}
if (array_key_exists('time', item)) if ('time' in item)
| at !{item['time']} UTC | at !{item.time} UTC
else if (item['type'] == "comment") else if (item.type == "comment")
.comment .comment
p.quote p.quote
if (array_key_exists('title', item)) if ('title' in item)
strong !{item['title']} strong !{item.title}
br br
if (array_key_exists('content', item)) if ('content' in item)
| !{item['content']} | !{item.content}
p.sub p.sub
a(href="{item['source']}") Commented a(href=item.source) Commented
if (array_key_exists('author_name', item)) if ('author_name' in item)
| by !{item['author_name']} | by !{item.author_name}
if (array_key_exists('date', item)) if ('date' in item)
| on !{item['date']} | on !{item.date}
if (array_key_exists('time', item)) if ('time' in item)
| at !{item['time']} UTC | at !{item.time} UTC
mixin discussionLink(item) mixin discussionLink(item)
p p
a(href="{item}") !{item} a(href=item) !{item}
block content block content
header header
@ -60,13 +60,13 @@ block content
if ('discussion' in post && post.discussion) if ('discussion' in post && post.discussion)
.discussion.subsection .discussion.subsection
h2 Join the discussion h2 Join the discussion
each item in post["discussion"] each item in post.discussion
+discussionLink(item) +discussionLink(item)
.webmentions.subsection .webmentions.subsection
h2 Webmentions h2 Webmentions
if (post.hasWebmentions) if post.hasWebmentions
each item in post["webmentions"] each item in post.webmentions
+webmention(item) +webmention(item)
else else
p This post has not been mentioned yet. p This post has not been mentioned yet.

View File

@ -18,4 +18,4 @@ block content
main main
.list .list
each item in vinyl.albums each item in vinyl.albums
+entry(item) +entrysitem)

View File

@ -1,13 +1,5 @@
extends templates/main extends templates/main
mixin foss_contribution($item)
p
a(href="{$item['url-repo']}") !{$item['repo']}
| —
a(href="{$item['url-item']}") #!{$item['id']}
br
| !{$item['title']}
block content block content
header header
h1 h1
@ -19,8 +11,15 @@ block content
a(href="/work") work a(href="/work") work
main main
h2 &gt;&gt; VCS accounts h2 &gt;&gt; Open Source developer
h3 Projects
p
| Currently working on
a(href="https://keyoxide.org") Keyoxide
| .
h3 VCS accounts
.wrapper-table .wrapper-table
table table
tbody tbody
@ -36,9 +35,3 @@ block content
td Github td Github
td td
a(href="https://github.com/YarmoM" rel="me") @YarmoM a(href="https://github.com/YarmoM" rel="me") @YarmoM
h2 &gt;&gt; Contributions
each $item in $foss
+foss_contribution($item)