This commit is contained in:
Yarmo Mackenbach 2020-09-24 21:18:02 +02:00
parent 57b786dfeb
commit 83f00f9a79
34 changed files with 1916 additions and 1051 deletions

3
.gitignore vendored
View File

@ -1,3 +1,2 @@
.well-known
vendor
cache
node_modules

View File

@ -1,15 +0,0 @@
{
"require": {
"pug-php/pug": "^3.4",
"altorouter/altorouter": "^2.0",
"pagerange/metaparsedown": "^1.0",
"bhaktaraz/php-rss-generator": "dev-master",
"symfony/yaml": "^5.1",
"tubalmartin/cssmin": "^4.1"
},
"scripts": {
"minifyCSS": [
"php scripts/minifyCSS.php"
]
}
}

1023
composer.lock generated

File diff suppressed because it is too large Load Diff

21
index.js Normal file
View File

@ -0,0 +1,21 @@
const express = require('express')
const fs = require('fs')
const app = express()
require('dotenv').config()
app.set('env', process.env.NODE_ENV || "production")
app.set('view engine', 'pug')
app.set('port', process.env.PORT || 3000)
app.use('/', require('./routes/main'))
app.use('/', require('./routes/static'))
// app.use('/server', require('./routes/server'))
// app.use('/encrypt', require('./routes/encrypt'))
// app.use('/verify', require('./routes/verify'))
// app.use('/proofs', require('./routes/proofs'))
// app.use('/util', require('./routes/util'))
// app.use('/', require('./routes/profile'))
app.listen(app.get('port'), () => {
console.log(`Node server listening at http://localhost:${app.get('port')}`)
})

6
nodemon.json Normal file
View File

@ -0,0 +1,6 @@
{
"ignore": [],
"env": {
"NODE_ENV": "development"
}
}

1752
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

32
package.json Normal file
View File

@ -0,0 +1,32 @@
{
"name": "yarmo.eu",
"version": "0.1.0",
"description": "Yarmo.eu website",
"main": "index.js",
"scripts": {
"start": "node index",
"dev": "nodemon --config nodemon.json index"
},
"repository": {
"type": "git",
"url": "https://git.yarmo.eu/yarmo/yarmo.eu"
},
"keywords": [],
"author": "Yarmo Mackenbach <yarmo@yarmo.eu> (https://yarmo.eu)",
"license": "AGPL-3.0-or-later",
"dependencies": {
"dotenv": "^8.2.0",
"express": "^4.17.1",
"express-validator": "^6.6.1",
"jstransformer-markdown-it": "^2.1.0",
"luxon": "^1.25.0",
"markdown-it-anchor": "^5.3.0",
"markdown-it-table-of-contents": "^0.4.4",
"markdown-it-title": "^3.0.0",
"pug": "^3.0.0",
"yaml-front-matter": "^4.1.0"
},
"devDependencies": {
"nodemon": "^2.0.4"
}
}

View File

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

View File

Before

Width:  |  Height:  |  Size: 838 B

After

Width:  |  Height:  |  Size: 838 B

View File

Before

Width:  |  Height:  |  Size: 850 B

After

Width:  |  Height:  |  Size: 850 B

View File

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

Before

Width:  |  Height:  |  Size: 327 B

After

Width:  |  Height:  |  Size: 327 B

View File

Before

Width:  |  Height:  |  Size: 990 B

After

Width:  |  Height:  |  Size: 990 B

View File

Before

Width:  |  Height:  |  Size: 95 KiB

After

Width:  |  Height:  |  Size: 95 KiB

View File

Before

Width:  |  Height:  |  Size: 31 KiB

After

Width:  |  Height:  |  Size: 31 KiB

View File

Before

Width:  |  Height:  |  Size: 3.7 KiB

After

Width:  |  Height:  |  Size: 3.7 KiB

View File

Before

Width:  |  Height:  |  Size: 46 KiB

After

Width:  |  Height:  |  Size: 46 KiB

View File

Before

Width:  |  Height:  |  Size: 416 B

After

Width:  |  Height:  |  Size: 416 B

View File

Before

Width:  |  Height:  |  Size: 658 B

After

Width:  |  Height:  |  Size: 658 B

40
routes/main.js Normal file
View File

@ -0,0 +1,40 @@
const router = require('express').Router()
const fs = require('fs')
const mw = require('../server/middlewares')
router.get('/', mw.getBlogPosts, (req, res) => {
res.render('index', { title: 'yarmo.eu' })
})
router.get('/getting-started', (req, res) => {
let rawContent = fs.readFileSync(`./content/getting-started.md`, "utf8")
const content = md.render(rawContent)
res.render(`basic`, { title: `Getting started - Keyoxide`, content: content })
})
router.get('/faq', (req, res) => {
const mdAlt = require('markdown-it')({typographer: true})
mdAlt.use(require("markdown-it-anchor"), { "level": 2, "permalink": true, "permalinkClass": 'header-anchor', "permalinkSymbol": '¶', "permalinkBefore": false })
mdAlt.use(require("markdown-it-table-of-contents"), { "includeLevel": [2], "listType": "ul" })
let rawContent = fs.readFileSync(`./content/faq.md`, "utf8")
rawContent = rawContent.replace('${domain}', req.app.get('domain'))
const content = mdAlt.render(rawContent)
res.render(`basic`, { title: `Frequently Asked Questions - Keyoxide`, content: content })
})
router.get('/guides', (req, res) => {
res.render('guides', { title: `Guides - Keyoxide` })
})
router.get('/guides/:guideId', (req, res) => {
let env = {}
let rawContent = fs.readFileSync(`./content/guides/${req.params.guideId}.md`, "utf8", (err, data) => {
if (err) throw err
return data
})
const content = md.render(rawContent, env)
res.render(`basic`, { title: `${env.title} - Keyoxide`, content: content })
})
module.exports = router

8
routes/static.js Normal file
View File

@ -0,0 +1,8 @@
const express = require('express')
const router = require('express').Router()
const path = require('path')
router.use('/favicon.png', express.static(path.join(__dirname, '../', 'public', 'favicon.png')))
router.use('/static', express.static(path.join(__dirname, '../', 'public')))
module.exports = router

30
server/middlewares.js Normal file
View File

@ -0,0 +1,30 @@
const path = require('path')
const fs = require('fs')
const util = require('./util')
const md = require('markdown-it')({ typographer: true })
const yamlFront = require('yaml-front-matter')
const { DateTime } = require('luxon')
module.exports.getBlogPosts = async (req, res, next) => {
let data = []
for await (const f of util.getFiles(path.join(__dirname, '../', 'content', 'blog'))) {
const rawContent = fs.readFileSync(f, 'utf8')
const fm = yamlFront.loadFront(rawContent)
data.push({
type: 'blog',
title: fm['title'],
author: fm['author'],
urlrel: `/post/${fm['slug']}`,
url: `https://yarmo.eu/post/${fm['slug']}`,
slug: fm['slug'],
date: fm['date'],
// date_formatted: DateTime.fromFormat(fm['date'], 'yyyy-LL-dd hh:mm:ss').toFormat('yyyy-LL-dd'),
date_formatted: DateTime.fromFormat(fm['date'], 'yyyy-LL-dd hh:mm:ss').setLocale("en").toLocaleString(DateTime.DATE_MED),
published: fm['published'],
discussion: fm['discussion'],
content: md.render(fm.__content)
})
}
res.locals.blogPosts = data.reverse()
next()
}

17
server/util.js Normal file
View File

@ -0,0 +1,17 @@
const { resolve } = require('path')
const { readdir } = require('fs').promises
const fs = require('fs')
async function* getFiles(dir) {
const dirents = await readdir(dir, { withFileTypes: true })
for (const dirent of dirents) {
const res = resolve(dir, dirent.name)
if (dirent.isDirectory()) {
yield* getFiles(res)
} else {
yield res
}
}
}
module.exports.getFiles = getFiles

View File

@ -1,12 +1,12 @@
extends layout
extends templates/main
mixin entry($item)
mixin entry(item)
article.longform_list__item.h-entry
p
a(href="{$item['urlrel']}").p-name.u-url !{$item['title']}
a(href="{item['urlrel']}").p-name.u-url !{item['title']}
br
| Posted on
time(datetime="{$item['date']}").dt-published !{$item['date_formatted']}
time(datetime="{item['date']}").dt-published !{item['date_formatted']}
block content
.h-card
@ -34,5 +34,5 @@ block content
include id
.longform_list.h-feed
each $item in $posts
+entry($item)
each item in blogPosts
+entry(item)

View File

@ -4,12 +4,10 @@ html
meta(name="viewport", content="width=device-width, initial-scale=1.0")
meta(name="theme-color", content="#4ab4ab")
meta(http-equiv="X-UA-Compatible", content="ie=edge")
title #{$title}
title #{title}
link(rel="stylesheet", href="/static/dank-mono.css")
style
dyninclude "static/norm.css"
style
dyninclude "static/style.css"
link(rel="stylesheet", href="/static/norm.css")
link(rel="stylesheet", href="/static/style.css")
link(rel="shortcut icon", href="/favicon.png")
link(rel="alternate", href="/rss/all", title="RSS blog feed for yarmo.eu", type="application/rss+xml")
link(rel="webmention", href="https://webm.yarmo.eu/receive")