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=",
"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": {
"version": "2.1.0",
"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",
"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": {
"version": "6.1.0",
"resolved": "https://registry.npmjs.org/cacheable-request/-/cacheable-request-6.1.0.tgz",
@ -251,6 +266,11 @@
"integrity": "sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==",
"dev": true
},
"caseless": {
"version": "0.12.0",
"resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz",
"integrity": "sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw="
},
"chalk": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-3.0.0.tgz",
@ -834,6 +854,11 @@
"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": {
"version": "1.0.0",
"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)",
"license": "AGPL-3.0-or-later",
"dependencies": {
"bent": "^7.3.10",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"express-validator": "^6.6.1",

View File

@ -4,24 +4,7 @@ const _ = require('lodash')
const mw = require('../server/middlewares')
const util = require('../server/util')
router.param('slug', async (req, res, next, slug) => {
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.param('slug', mw.getPostBySlug)
router.get('/', mw.getBlogPosts, (req, res) => {
res.render('blog', { title: 'Blog — yarmo.eu' })
@ -29,9 +12,15 @@ router.get('/', mw.getBlogPosts, (req, res) => {
router.get('/blog', mw.getBlogPosts, (req, res) => {
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) => {
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) => {
res.render('post', { title: `${res.locals.post.title} — yarmo.eu` })
})

View File

@ -13,6 +13,18 @@ module.exports.getNotes = async (req, res, 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) => {
const file = fs.readFileSync(path.join(__dirname, '../', 'content', 'music', 'vinyl.yaml'), 'utf8')
res.locals.vinyl = YAML.parse(file)

View File

@ -2,6 +2,8 @@ const fs = require('fs')
const { readdir } = require('fs').promises
const path = require('path')
const { resolve } = require('path')
const bent = require('bent')
const getJSON = bent('json')
const _ = require('lodash')
const md = require('markdown-it')({ typographer: true })
const yamlFront = require('yaml-front-matter')
@ -76,6 +78,27 @@ const getNotes = async (opts) => {
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) => {
if (!opts) { opts = {} }
opts.include = 'include' in opts ? opts.include : ['blog', 'notes']
@ -141,5 +164,7 @@ module.exports = {
getFiles: getFiles,
getBlogPosts: getBlogPosts,
getNotes: getNotes,
getPost: getPost,
getWebmentions: getWebmentions,
getRSS: getRSS
}

View File

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

View File

@ -1,21 +1,21 @@
extends templates/main
mixin entry(item)
.list__item
p !{item['artist']} - !{item['title']} (!{item['year']})
.list__item
p !{item['artist']} - !{item['title']} (!{item['year']})
block content
header
h1 Yarmo's vinyl collection
nav
| &gt;&gt;
a(href="/about") about me
| &gt;
a(href="/music") music
| &gt;
a(href="/vinyl") vinyl
header
h1 Yarmo's vinyl collection
nav
| &gt;&gt;
a(href="/about") about me
| &gt;
a(href="/music") music
| &gt;
a(href="/vinyl") vinyl
main
.list
each item in vinyl.albums
+entry(item)
main
.list
each item in vinyl.albums
+entrysitem)

View File

@ -1,44 +1,37 @@
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
header
h1
| Work
nav
| &gt;&gt;
a(href="/about") about me
| &gt;
a(href="/work") work
main
h2 &gt;&gt; VCS accounts
.wrapper-table
table
tbody
tr
td Codeberg
td
a(href="https://codeberg.org/yarmo" rel="me") @yarmo
tr
td GitLab
td
a(href="https://gitlab.com/yarmo" rel="me") @yarmo
tr
td Github
td
a(href="https://github.com/YarmoM" rel="me") @YarmoM
h2 &gt;&gt; Contributions
each $item in $foss
+foss_contribution($item)
header
h1
| Work
nav
| &gt;&gt;
a(href="/about") about me
| &gt;
a(href="/work") work
main
h2 &gt;&gt; Open Source developer
h3 Projects
p
| Currently working on
a(href="https://keyoxide.org") Keyoxide
| .
h3 VCS accounts
.wrapper-table
table
tbody
tr
td Codeberg
td
a(href="https://codeberg.org/yarmo" rel="me") @yarmo
tr
td GitLab
td
a(href="https://gitlab.com/yarmo" rel="me") @yarmo
tr
td Github
td
a(href="https://github.com/YarmoM" rel="me") @YarmoM