forked from Einundzwanzig-Podcast/einundzwanzig.space
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pug.config.js
38 lines (36 loc) · 1.42 KB
/
pug.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// initialize markdown rendering
const helpers = require('./helpers')
const IS_DEV = process.env.NODE_ENV === 'development'
const HOST = IS_DEV ? 'http://localhost:3000' : getBaseUrl()
const random = max => Math.floor(Math.random() * Math.floor(max))
const shuffle = arr => { for (let i = arr.length - 1; i > 0; i--) { const j = Math.floor(Math.random() * i); const temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; }; return arr }
const formatDate = date => (new Date(date)).toISOString().replace(/T.*/, '').split('-').reverse().join('.')
const linkTarget = url => url.startsWith('http') ? '_blank' : null
const assetPath = path => {
if (path.startsWith('http')) return path
let revs
try { revs = require('./generated/rev.json') } catch (error) { }
return `${(revs && revs[path]) || path}`
}
const assetUrl = (path, protocol = 'https') => {
if (IS_DEV && !path.startsWith('http')) protocol = 'http'
const base = path.startsWith('http') ? '' : HOST
let url = `${base}${assetPath(path)}`
if (!url.startsWith(`${protocol}:`)) url = url.replace(/^.*:/, `${protocol}:`)
return url
}
function getBaseUrl () {
const { DEPLOY_PRIME_URL, URL } = process.env
const branchUrl = DEPLOY_PRIME_URL || URL || ''
return !branchUrl.match('master--einundzwanzig') ? branchUrl : 'https://einundzwanzig.space'
}
module.exports = {
basedir: './src/includes',
random,
shuffle,
assetUrl,
assetPath,
formatDate,
linkTarget,
...helpers
}