Rewrote gulp/content

This commit is contained in:
Jocelyn Badgley (Twipped) 2020-02-21 20:05:52 -08:00
parent 7a3eeae52c
commit 260138f25d
11 changed files with 702 additions and 1075 deletions

3
.gitignore vendored
View File

@ -6,8 +6,7 @@ node_modules
/.awspublish-*
/bs-manifest.json
/bs-cache
/posts.json
/posts-sans.json
/pages.json
/if-*
/twitter-cache.json
/terraform/*.tfstate*

84
gulp/content/files.js Normal file
View File

@ -0,0 +1,84 @@
const path = require('path');
const glob = require('../lib/glob');
const memoize = require('memoizepromise');
const getDimensions = require('../lib/dimensions');
const { keyBy } = require('lodash');
const RESOLUTIONS = [ 2048, 1024, 768, 576, 300, 100 ];
module.exports = exports = function () {
return memoize(async (cwd, siteDir) => {
const imageFiles = (await glob('{*,_images/*}.{jpeg,jpg,png,gif,mp4}', { cwd }));
const images = (await Promise.all(imageFiles.map(async (imgpath) => {
const ext = path.extname(imgpath);
let basename = path.basename(imgpath, ext);
if (basename === 'titlecard') return;
if (ext === '.mp4') {
return {
name: basename,
type: 'movie',
full: path.join(siteDir, `${basename}${ext}`),
};
}
const dimensions = await getDimensions(path.resolve(cwd, imgpath));
const { width, height } = dimensions;
dimensions.ratioH = Math.round((height / width) * 100);
dimensions.ratioW = Math.round((width / height) * 100);
if (dimensions.ratioH > 100) {
dimensions.orientation = 'tall';
} else if (dimensions.ratioH === 100) {
dimensions.orientation = 'square';
} else {
dimensions.orientation = 'wide';
}
if (basename[0] === '_') {
basename = basename.slice(1);
}
const filetype = {
'.jpeg': 'jpeg',
'.jpg': 'jpeg',
'.png': 'png',
'.gif': 'gif',
}[ext];
const sizes = [
{
url: path.join(siteDir, `${basename}.${filetype}`),
width: dimensions.width,
height: dimensions.height,
},
];
for (const w of RESOLUTIONS) {
if (w > dimensions.width) continue;
sizes.push({
url: path.join(siteDir, `${basename}.${w}w.${filetype}`),
width: w,
height: Math.ceil((w / dimensions.width) * dimensions.height),
});
}
sizes.reverse();
return {
name: basename,
type: 'image',
sizes,
};
}))).filter(Boolean);
const titlecard = (await glob('titlecard.{jpeg,jpg,png,gif}', { cwd }))[0];
return {
images: keyBy(images, 'name'),
titlecard: titlecard ? path.join(siteDir, titlecard) : '/images/titlecard.png',
};
});
};

305
gulp/content/index.js Normal file
View File

@ -0,0 +1,305 @@
const path = require('path');
const glob = require('../lib/glob');
const { chunk, uniq, difference } = require('lodash');
const Promise = require('bluebird');
const fs = require('fs-extra');
const log = require('fancy-log');
const tweetparse = require('../lib/tweetparse');
const getEngines = require('./renderers');
const Twitter = require('twitter-lite');
const frontmatter = require('front-matter');
const createFileLoader = require('./files');
const { URL } = require('url');
const ROOT = path.resolve(__dirname, '../..');
exports.parse = async function parsePageContent () {
const [ files, twitter, twitterBackup, twitterCache, { siteInfo } ] = await Promise.all([
glob('pages/**/*.{md,hbs,html,xml}', { cwd: ROOT }),
fs.readJson(resolve('twitter-config.json')).catch(() => null)
.then(getTwitterClient),
fs.readJson(resolve('twitter-backup.json')).catch(() => {}),
fs.readJson(resolve('twitter-cache.json')).catch(() => {}),
fs.readJson(resolve('package.json')).catch(() => ({})),
]);
const loadFiles = createFileLoader();
const tweetsNeeded = [];
let pages = await Promise.map(files, async (filepath) => {
const { dir, name, ext } = path.parse(filepath);
const basename = path.basename(filepath);
// this is an include, skip it.
if (name[0] === '_') return;
const cwd = resolve(dir);
const input = resolve(filepath);
const outDir = path.join('dist', dir.slice(6));
const siteDir = `/${dir.slice(6)}`;
// if cwd === ROOT then we're in the bottom directory and there is no base
const base = path.relative(cwd, ROOT) && path.basename(dir);
/* Load Page Content **************************************************/
const [ raw, { ctime, mtime }, { images, titlecard } ] = await Promise.all([
fs.readFile(input).catch(() => null),
stat(input),
loadFiles(cwd, siteDir),
]);
// empty file
if (!raw) return;
try {
var { attributes: meta, body } = frontmatter(raw.toString('utf8'));
} catch (e) {
log.error('Error while parsing frontmatter for ' + filepath, e);
return;
}
// page is marked to be ignored, skip it.
if (meta.ignore) return;
meta.path = filepath;
meta.cwd = cwd;
meta.base = base;
meta.outDir = outDir;
meta.input = input;
meta.source = body;
meta.dateCreated = meta.date && new Date(meta.date) || ctime;
meta.dateModified = mtime;
meta.siteDir = siteDir;
meta.name = name;
meta.ext = ext;
meta.titlecard = titlecard;
meta.images = images;
var flags = new Set(meta.classes || []);
var isIndexPage = meta.isIndex = (name === 'index');
var isRootPage = meta.isRoot = (siteDir === '/');
var isCleanUrl = meta.isCleanUrl = [ '.hbs', '.md' ].includes(ext);
if ([ '.hbs', '.html', '.xml' ].includes(ext)) {
meta.engine = 'hbs';
} else if (ext === '.md') {
meta.engine = 'md';
} else {
meta.engine = 'raw';
}
flags.add(titlecard ? 'has-titlecard' : 'no-titlecard');
flags.add(meta.title ? 'has-title' : 'no-title');
flags.add(meta.subtitle ? 'has-subtitle' : 'no-subtitle');
flags.add(meta.description ? 'has-descrip' : 'no-descrip');
let slug, output, jsonOutput;
if (isRootPage) {
if (isCleanUrl) {
slug = '';
output = resolve(outDir, name, 'index.html');
jsonOutput = resolve(outDir, name + '.json');
} else {
slug = '';
output = resolve(outDir, basename);
jsonOutput = resolve(outDir, basename + '.json');
}
} else if (isCleanUrl) {
slug = name;
if (isIndexPage) {
output = resolve(outDir, 'index.html');
} else {
output = resolve(outDir, name, 'index.html');
}
jsonOutput = resolve(outDir, name + '.json');
} else {
slug = base;
output = resolve(outDir, basename);
jsonOutput = resolve(outDir, basename + '.json');
}
meta.slug = slug;
meta.output = output;
meta.json = jsonOutput;
const url = new URL(siteInfo.siteUrl);
if ([ '.hbs', '.md' ].includes(ext)) {
url.pathname = path.join(siteDir, slug);
} else if (isIndexPage) {
url.pathname = siteDir;
} else {
url.pathname = path.join(siteDir, path.basename(filepath));
}
meta.url = url.pathname;
meta.fullurl = url.toString();
/* Process Tweets **************************************************/
const tweets = [];
if (meta.tweet) {
meta.tweet = [ meta.tweet ].flat(1).map(parseTweetId);
tweets.push(...meta.tweet);
}
if (meta.tweets) {
meta.tweets = meta.tweets.map(parseTweetId);
tweets.push(...meta.tweets);
}
for (const id of tweets) {
if (!twitterCache[id]) {
tweetsNeeded.push(id);
}
}
meta.tweets = tweets;
flags.add(tweets.length ? 'has-tweets' : 'no-tweets');
/* Process Flags **************************************************/
meta.classes = Array.from(flags);
meta.flags = meta.classes.reduce((res, item) => {
var camelCased = item.replace(/-([a-z])/g, (g) => g[1].toUpperCase());
res[camelCased] = true;
return res;
}, {});
return meta;
});
pages = pages.filter(Boolean);
/* Load Missing Tweets **************************************************/
if (tweetsNeeded.length) {
log('Fetching tweets: ' + tweetsNeeded.join(', '));
const arriving = await Promise.all(chunk(uniq(tweetsNeeded), 99).map(twitter));
const loaded = [];
for (const tweet of arriving.flat(1)) {
if (!twitterBackup[tweet.id_str]) twitterBackup[tweet.id_str] = tweet;
twitterCache[tweet.id_str] = tweetparse(tweet);
loaded.push(tweet.id_str);
}
const absent = difference(tweetsNeeded, loaded);
for (const id of absent) {
if (twitterBackup[id]) {
log('Pulled tweet from backup ' + id);
twitterCache[id] = tweetparse(twitterBackup[id]);
continue;
}
log.error('Could not find tweet ' + id);
}
}
/* Apply Tweets to Pages **************************************************/
const twitterMedia = [];
// now loop through pages and substitute the tweet data for the ids
for (const page of pages) {
if (!page.tweets || !page.tweets.length) continue;
page.tweets = page.tweets.reduce((dict, tweetid) => {
const tweet = twitterCache[tweetid];
if (!tweet) {
log.error(`Tweet ${tweetid} is missing from the cache.`);
return dict;
}
dict[tweetid] = tweet;
twitterMedia.push( ...tweet.media );
return dict;
}, {});
}
await Promise.all([
fs.writeFile(path.join(ROOT, 'pages.json'), JSON.stringify(pages, null, 2)),
fs.writeFile(path.join(ROOT, 'twitter-media.json'), JSON.stringify(twitterMedia, null, 2)),
fs.writeFile(path.join(ROOT, 'twitter-cache.json'), JSON.stringify(twitterCache, null, 2)),
fs.writeFile(path.join(ROOT, 'twitter-backup.json'), JSON.stringify(twitterBackup, null, 2)),
]);
return pages;
};
exports.write = async function writePageContent ({ prod }) {
const [ pages, { siteInfo }, engines ] = await Promise.all([
fs.readJson(resolve('pages.json')),
fs.readJson(resolve('package.json')),
getEngines(prod),
]);
await Promise.map(pages, async (page) => {
var data = {
...page,
meta: page,
page: {
domain: siteInfo.domain,
title: page.title
? (page.title + (page.subtitle ? ', ' + page.subtitle : '') + ' :: ' + siteInfo.title)
: siteInfo.title,
},
local: {
cwd: page.cwd,
root: ROOT,
basename: path.basename(page.input),
},
pages,
};
const html = engines[page.engine](data.source, data).toString();
const json = page.json && {
url: page.fullurl,
title: page.title,
subtitle: page.subtitle,
description: page.description,
tweets: page.tweets,
images: page.images,
dateCreated: page.dateCreated,
dateModified: page.dateModified,
titlecard: page.titlecard,
};
await fs.ensureDir(path.dirname(page.output));
await Promise.all([
fs.writeFile(page.output, Buffer.from(html)),
json && fs.writeFile(page.json, Buffer.from(prod ? JSON.stringify(json) : JSON.stringify(json, null, 2))),
]);
});
};
exports.write.prod = function writePageContentForProduction () { return exports.write({ prod: true }); };
/* Utility Functions **************************************************/
const tweeturl = /https?:\/\/twitter\.com\/(?:#!\/)?(?:\w+)\/status(?:es)?\/(\d+)/i;
const tweetidcheck = /^\d+$/;
function parseTweetId (tweetid) {
// we can't trust an id that isn't a string
if (typeof tweetid !== 'string') return false;
const match = tweetid.match(tweeturl);
if (match) return match[1];
if (tweetid.match(tweetidcheck)) return tweetid;
return false;
}
function resolve (fpath, ...args) {
if (fpath[0] === '/') fpath = fpath.slice(1);
return path.resolve(ROOT, fpath, ...args);
}
function getTwitterClient (config) {
if (!config) return () => [];
const client = new Twitter(config);
return (tweetids) => client
.get('statuses/lookup', { id: tweetids.join(','), tweet_mode: 'extended' })
.catch((e) => { log.error(e); return []; });
}
const stat = (f) => fs.stat(f).catch(() => undefined);

254
gulp/content/renderers.js Normal file
View File

@ -0,0 +1,254 @@
const path = require('path');
const ROOT = path.resolve(__dirname, '../..');
const fs = require('fs-extra');
const log = require('fancy-log');
const { minify } = require('html-minifier-terser');
const handlebars = require('handlebars');
const HandlebarsKit = require('hbs-kit');
HandlebarsKit.load(handlebars);
const slugs = require('slugify');
const slugify = (s) => slugs(s, { remove: /[*+~.,()'"!?:@/\\]/g }).toLowerCase();
const striptags = require('string-strip-html');
const markdownIt = require('markdown-it');
const markdownEngines = {
full: markdownIt({
html: true,
linkify: true,
typographer: true,
})
.enable('image')
.use(require('markdown-it-anchor'), {
permalink: true,
permalinkClass: 'header-link',
permalinkSymbol: '<img src="/images/svg/paragraph.svg">',
slugify,
})
.use(require('../lib/markdown-raw-html')),
preview: markdownIt({
html: false,
linkify: false,
typographer: true,
})
.use(require('../lib/markdown-token-filter')),
};
function markdown (mode, input, env) {
input = input.replace(/\{!\{([\s\S]*?)\}!\}/mg, (match, contents) => {
try {
const result = handlebars.compile(contents)(env);
return '|||' + result + '|||';
} catch (e) {
log.error(e);
return '';
}
});
if (mode === 'preview') {
input = striptags(input
.replace(/<!--\[[\s\S]*?\]-->/g, '')
.replace(/|||[\s\S]*?|||/gi, ''),
).trim();
if (input.length > 1000) input = input.slice(0, 1000) + '…';
input = input ? markdownEngines[mode].render(input) : '';
} else {
input = input.replace(/<!--[[\]]-->/g, '');
}
return input ? markdownEngines[mode].render(input, env) : '';
}
function stripIndent (input) {
const match = input.match(/^[^\S\n]*(?=\S)/gm);
const indent = match && Math.min(...match.map((el) => el.length));
if (indent) {
const regexp = new RegExp(`^.{${indent}}`, 'gm');
input = input.replace(regexp, '');
}
return input;
}
const MINIFY_CONFIG = {
conservativeCollapse: true,
collapseWhitespace: true,
minifyCSS: true,
removeComments: true,
removeRedundantAttributes: true,
};
const HANDLEBARS_PARTIALS = {
layout: 'templates/layout.hbs',
};
module.exports = exports = async function (prod) {
for (const [ name, file ] of Object.entries(HANDLEBARS_PARTIALS)) {
try {
const contents = await fs.readFile(path.resolve(ROOT, file));
const template = handlebars.compile(contents.toString('utf8'));
handlebars.registerPartial(name, template);
} catch (e) {
log.error('Could not execute load partial ' + path.relative(ROOT, file), e);
}
}
const pageTemplateRaw = await fs.readFile(path.join(ROOT, 'templates/post.hbs'));
if (!pageTemplateRaw) throw new Error('Post template was empty?');
try {
var pageTemplate = handlebars.compile(pageTemplateRaw.toString('utf8'));
} catch (e) {
log.error('Crash while loading post template', e);
}
const revManifest = prod && await fs.readJson(path.join(ROOT, 'rev-manifest.json')).catch(() => {}).then((r) => r || {});
const helpers = new Injectables(prod, revManifest);
handlebars.registerHelper('import', helpers.import());
handlebars.registerHelper('markdown', helpers.markdown());
handlebars.registerHelper('icon', helpers.icon());
handlebars.registerHelper('prod', helpers.production());
handlebars.registerHelper('rev', helpers.rev());
const shrink = (input) => (prod ? minify(input, MINIFY_CONFIG) : input);
const result = {
hbs: (source, env) => {
const template = handlebars.compile(source);
return shrink(template(env));
},
md: (source, env) => shrink(pageTemplate({ ...env, contents: markdown('full', source, env) })),
raw: (source) => shrink(source),
preview: (source, env) => markdown('preview', source, env),
};
// result.handlebars.engine = handlebars;
// result.markdown.engine = markdownEngines.full;
return result;
};
class Injectables {
constructor (prod, revManifest) {
this.prod = prod;
this.revManifest = revManifest;
this.injections = {};
}
_parsePath (tpath, local, type) {
if (tpath[0] === '/') tpath = path.join(local.root, tpath);
else if (tpath[0] === '~') tpath = path.join(local.root, 'templates', tpath.slice(2));
else tpath = path.resolve(local.cwd, tpath);
if (type && !tpath.endsWith(type)) tpath += '.' + type;
return tpath;
}
_template (tpath, make) {
if (this.injections[tpath]) return this.injections[tpath];
if (!fs.existsSync(tpath)) {
log.error('Injectable does not exist: ' + path.relative(ROOT, tpath));
return '';
}
let contents;
try {
contents = fs.readFileSync(tpath).toString('utf8');
if (make) contents = make(contents);
this.injections[tpath] = contents;
return contents;
} catch (e) {
log.error(e, 'An error occured while loading the injectable: ' + path.relative(ROOT, tpath));
}
return '';
}
rev () {
const self = this;
return function (url) {
if (!url) return '';
if (url[0] === '/') url = url.substr(1);
if (self.prod && self.revManifest[url]) return '/' + self.revManifest[url];
return '/' + url;
};
}
production () {
const self = this;
return function (options) {
if (!options.fn) return self.prod;
return self.prod ? options.fn(this) : options.inverse(this);
};
}
markdown () {
const self = this;
return function (...args) {
const { fn } = args.pop();
let contents;
if (fn) {
contents = stripIndent(fn(this));
} else {
let tpath = args.shift();
tpath = self._parsePath(tpath, this.local, 'md');
contents = self._template(tpath);
}
contents = markdown('full', contents, this);
return new handlebars.SafeString(contents);
};
}
import () {
const self = this;
return function (tpath, ...args) {
const { hash } = args.pop();
const value = args.shift();
const context = handlebars.createFrame(value || this);
Object.assign(context, hash || {});
tpath = self._parsePath(tpath, this.local, 'hbs');
try {
const contents = self._template(tpath, handlebars.compile)(context);
return new handlebars.SafeString(contents);
} catch (e) {
log.error('Could not execute import template ' + path.relative(ROOT, tpath), e);
return '';
}
};
}
icon () {
const self = this;
return function (name, ...args) {
const { hash } = args.pop();
const tpath = path.join(this.local.root, 'svg', name + '.svg');
try {
const contents = self._template(tpath, (s) =>
handlebars.compile(`<span class="svg-icon" {{#if size}}style="width:{{size}}px;height:{{size}}px"{{/if}}>${s}</span>`),
)({ size: hash && hash.size });
return new handlebars.SafeString(contents);
} catch (e) {
log.error('Could not execute import template ' + path.relative(ROOT, tpath), e);
return '';
}
};
}
}

View File

@ -1,579 +0,0 @@
const path = require('path');
const fs = require('fs-extra');
const { chunk, uniq, keyBy, difference, omit } = require('lodash');
const log = require('fancy-log');
const glob = require('./lib/glob');
const getDimensions = require('./lib/dimensions');
const memoize = require('memoizepromise');
const { URL } = require('url');
const { minify: htmlMinify } = require('html-minifier-terser');
const { src, dest } = require('gulp');
const frontmatter = require('gulp-front-matter');
const collect = require('gulp-collect');
const asyncthrough = require('./lib/through');
const ROOT = path.dirname(__dirname);
const DEST = 'dist';
const { siteInfo } = require('../package.json');
const markdown = require('markdown-it');
const striptags = require('string-strip-html');
const tweetparse = require('./lib/tweetparse');
const slugs = require('slugify');
const slugify = (s) => slugs(s, { remove: /[*+~.,()'"!?:@/\\]/g }).toLowerCase();
const handlebars = require('handlebars');
const HandlebarsKit = require('hbs-kit');
HandlebarsKit.load(handlebars);
const md = markdown({
html: true,
linkify: true,
typographer: true,
}).enable('image')
.use(require('markdown-it-anchor'), {
permalink: true,
permalinkClass: 'header-link',
permalinkSymbol: '<img src="/images/svg/paragraph.svg">',
slugify,
})
.use(require('./lib/markdown-raw-html'))
;
const mdPreview = markdown({
html: false,
linkify: false,
typographer: true,
})
.use(require('./lib/markdown-token-filter'))
;
let twitterClient;
const Twitter = require('twitter-lite');
try {
twitterClient = new Twitter(require('../twitter.json'));
} catch (e) {
twitterClient = null;
}
function twitter (tweetids) {
if (!twitterClient) return [];
return twitterClient.get('statuses/lookup', { id: tweetids.join(','), tweet_mode: 'extended' })
.catch((e) => { log.error(e); return []; });
}
async function reloadLayouts () {
const layouts = {
layout: 'templates/layout.hbs.html',
};
let pending = Object.entries(layouts)
.map(async ([ name, file ]) =>
[ name, (await fs.readFile(path.resolve(ROOT, file))).toString('utf8') ],
);
pending = await Promise.all(pending);
pending.forEach(([ name, file ]) => handlebars.registerPartial(name, handlebars.compile(file)));
const injections = {};
handlebars.registerHelper('inject', function (tpath, ...args) {
const { hash } = args.pop();
const context = handlebars.createFrame(args[0] || this);
Object.assign(context, hash || {});
if (tpath[0] === '/') tpath = path.join(this.local.root, tpath);
else if (tpath[0] === '~') tpath = path.join(this.local.root, 'templates', tpath.slice(2));
else tpath = path.resolve(this.local.cwd, tpath);
tpath += '.hbs';
if (!injections[tpath]) {
if (!fs.existsSync(tpath)) {
log.error('Template does not exist for injection ' + path.relative(ROOT, tpath));
return '';
}
try {
injections[tpath] = handlebars.compile(fs.readFileSync(tpath).toString('utf8'));
} catch (e) {
log.error('Could not load injection template ' + path.relative(ROOT, tpath), e);
return '';
}
}
try {
return new handlebars.SafeString(injections[tpath](context));
} catch (e) {
log.error('Could not execute injection template ' + path.relative(ROOT, tpath), e);
return '';
}
});
handlebars.registerHelper('icon', function (name, ...args) {
const { hash } = args.pop();
const tpath = path.join(this.local.root, 'svg', name + '.svg');
if (!injections[tpath]) {
if (!fs.existsSync(tpath)) {
log.error('Template does not exist for injection ' + path.relative(ROOT, tpath));
return '';
}
try {
const svg = fs.readFileSync(tpath).toString('utf8');
injections[tpath] = handlebars.compile(`<span class="svg-icon" {{#if size}}style="width:{{size}}px;height:{{size}}px"{{/if}}>${svg}</span>`);
} catch (e) {
log.error('Could not load injection template ' + path.relative(ROOT, tpath), e);
return '';
}
}
try {
return new handlebars.SafeString(injections[tpath]({ size: hash && hash.size }));
} catch (e) {
log.error('Could not execute injection template ' + path.relative(ROOT, tpath), e);
return '';
}
});
handlebars.registerHelper('markdown', function (...args) {
const { fn } = args.pop();
let original;
if (fn) {
original = fn(this);
const match = original.match(/^[^\S\n]*(?=\S)/gm);
const indent = match && Math.min(...match.map((el) => el.length));
if (indent) {
const regexp = new RegExp(`^.{${indent}}`, 'gm');
original = original.replace(regexp, '');
}
} else {
let tpath = args.shift();
if (!tpath) throw new Error('No content was provided for the Markdown helper');
if (tpath[0] === '/') tpath = path.join(this.local.root, tpath);
else tpath = path.resolve(this.local.cwd, tpath);
tpath += '.md';
if (!injections[tpath]) {
if (!fs.existsSync(tpath)) {
log.error('Markdown does not exist for injection ' + path.relative(ROOT, tpath));
return '';
}
try {
original = fs.readFileSync(tpath).toString('utf8');
injections[tpath] = original;
} catch (e) {
log.error('Could not load markdown file ' + path.relative(ROOT, tpath), e);
return '';
}
}
}
original = md.render(original);
return new handlebars.SafeString(original);
});
}
exports.loadLayout = async function loadLayout () {
await reloadLayouts();
handlebars.registerHelper('rev', (url) => {
if (!url) return '';
if (url[0] === '/') url = url.substr(1);
return '/' + url;
});
handlebars.registerHelper('prod', function (options) {
if (!options.inverse) return false;
return options.inverse(this);
});
};
exports.loadLayout.prod = async function loadLayoutForProd () {
const manifest = await fs.readJson(path.join(ROOT, 'rev-manifest.json')).catch(() => {}).then((r) => r || {});
await reloadLayouts();
handlebars.registerHelper('rev', (url) => {
if (!url) return '';
if (url[0] === '/') url = url.substr(1);
if (manifest[url]) return '/' + manifest[url];
return '/' + url;
});
handlebars.registerHelper('prod', function (options) {
if (!options.fn) return true;
return options.fn(this);
});
};
exports.pages = function buildPages ({ minify }) {
var postTemplate = handlebars.compile(String(fs.readFileSync(path.join(ROOT, '/templates/post.hbs.html'))));
const minifyConfig = {
conservativeCollapse: true,
collapseWhitespace: true,
minifyCSS: true,
removeComments: true,
removeRedundantAttributes: true,
};
return src([ 'pages/**/*.{md,html,xml}', '!pages/**/_*.{md,html}' ])
.pipe(frontmatter({
property: 'meta',
}))
.pipe(parseMeta())
.pipe(parseTweets())
.pipe(asyncthrough(async (stream, file) => {
const cwd = path.dirname(file.path);
let original = file.contents.toString('utf8').trim();
var data = {
...file.meta,
meta: file.meta,
page: {
domain: siteInfo.domain,
title: file.meta.title
? (file.meta.title + (file.meta.subtitle ? ', ' + file.meta.subtitle : '') + ' :: ' + siteInfo.title)
: siteInfo.title,
},
local: {
cwd,
root: ROOT,
basename: file.basename,
},
};
if ([ '.html', '.md' ].includes(file.extname)) {
const datajs = file.clone();
datajs.contents = Buffer.from(JSON.stringify(omit(file.meta, [ 'destination' ]), null, 2));
datajs.basename = path.basename(file.path, file.extname) + '.json';
stream.push(datajs);
}
if ([ '.html', '.xml' ].includes(file.extname)) {
// is a handlebars template
try {
const template = handlebars.compile(original);
let html = template(data);
if (minify) {
html = htmlMinify(html, minifyConfig);
}
file.contents = Buffer.from(html);
stream.push(file);
} catch (err) {
log.error('Encountered a crash while compiling ' + file.path, err);
}
return;
}
original = original.replace(/\{!\{([\s\S]*?)\}!\}/mg, (match, contents) => {
try {
const result = handlebars.compile(contents)(data);
return '|||' + result + '|||';
} catch (e) {
log.error(e);
return '';
}
});
if (file.extname === '.md') {
let contents, preview;
try {
contents = md.render(original.replace(/<!--[[\]]-->/g, '')).trim();
data.contents = contents;
preview = striptags(original
.replace(/<!--\[[\s\S]*?\]-->/g, '')
.replace(/|||[\s\S]*?|||/gi, ''),
).trim();
if (preview.length > 1000) preview = preview.slice(0, 1000) + '…';
preview = preview ? mdPreview.render(preview) : '';
data.preview = preview;
} catch (e) {
log.error(`Error while rendering ${file.path}`, e);
contents = preview = '';
}
if (preview) {
file.flags.add('has-preview');
if (preview.length < 400) file.flags.add('short-preview');
} else {
file.flags.add('no-preview');
}
const classes = Array.from(file.flags);
const flags = classes.reduce((res, item) => {
var camelCased = item.replace(/-([a-z])/g, (g) => g[1].toUpperCase());
res[camelCased] = true;
return res;
}, {});
data.classes = data.meta.classes = classes;
data.flags = data.meta.flags = flags;
file.path = file.meta.destination;
// is a markdown file
try {
let html = postTemplate(data);
if (minify) {
html = htmlMinify(html, minifyConfig);
}
file.contents = Buffer.from(html);
stream.push(file);
} catch (err) {
log.error(`Error while rendering html for ${file.path}`, err);
}
return;
}
}))
.pipe(dest(DEST));
};
exports.pages.prod = function buildPagesProd () { return exports.pages({ minify: true }); };
/** **************************************************************************************************************** **/
function parseMeta () {
const getFileData = memoize(async (cwd, siteCwd) => {
const imageFiles = (await glob('{*,_images/*}.{jpeg,jpg,png,gif,mp4}', { cwd }));
const images = (await Promise.all(imageFiles.map(async (imgpath) => {
const ext = path.extname(imgpath);
let basename = path.basename(imgpath, ext);
if (basename === 'titlecard') return;
if (ext === '.mp4') {
return {
name: basename,
type: 'movie',
full: path.join(siteCwd, `${basename}${ext}`),
};
}
const dimensions = await getDimensions(path.resolve(cwd, imgpath));
const { width, height } = dimensions;
dimensions.ratioH = Math.round((height / width) * 100);
dimensions.ratioW = Math.round((width / height) * 100);
if (dimensions.ratioH > 100) {
dimensions.orientation = 'tall';
} else if (dimensions.ratioH === 100) {
dimensions.orientation = 'square';
} else {
dimensions.orientation = 'wide';
}
if (basename[0] === '_') {
basename = basename.slice(1);
}
const filetype = {
'.jpeg': 'jpeg',
'.jpg': 'jpeg',
'.png': 'png',
'.gif': 'gif',
}[ext];
const sizes = [
{
url: path.join(siteCwd, `${basename}.${filetype}`),
width: dimensions.width,
height: dimensions.height,
},
];
for (const w of [ 2048, 1024, 768, 576, 300, 100 ]) {
if (w > dimensions.width) continue;
sizes.push({
url: path.join(siteCwd, `${basename}.${w}w.${filetype}`),
width: w,
height: Math.ceil((w / dimensions.width) * dimensions.height),
});
}
sizes.reverse();
return {
name: basename,
type: 'image',
sizes,
};
}))).filter(Boolean);
const titlecard = (await glob('titlecard.{jpeg,jpg,png,gif}', { cwd }))[0];
return {
images: keyBy(images, 'name'),
titlecard: titlecard ? path.join(siteCwd, titlecard) : false,
};
});
return asyncthrough(async (stream, file) => {
if (!file || (file.meta && file.meta.ignore)) return;
if (!file.meta) file.meta = {};
// if metadata has a date value, us it.
// otherwise use creation date
var date = new Date(file.meta.date);
if (!date) date = file.stat.ctime;
file.meta.data = date;
var cwd = path.dirname(file.path);
var siteCwd = file.meta.cwd = '/' + path.relative(path.join(ROOT, 'pages'), cwd);
var base = file.meta.base = path.basename(file.path, file.extname);
var flags = file.flags = new Set(file.meta.classes || []);
var isIndexPage = file.meta.isIndex = (base === 'index');
var isRootPage = file.meta.isRoot = (file.meta.cwd === '/');
if (isRootPage && isIndexPage) {
file.meta.slug = '';
file.meta.destination = path.join(path.dirname(file.path), 'index.html');
} else if (isRootPage || !isIndexPage) {
file.meta.slug = base;
file.meta.destination = path.join(path.dirname(file.path), base, 'index.html');
} else if (!isRootPage && isIndexPage) {
file.meta.slug = '';
file.meta.destination = path.join(path.dirname(file.path), 'index.html');
} else {
file.meta.slug = path.basename(cwd);
file.meta.destination = path.join(path.dirname(file.path), 'index.html');
}
const url = new URL(siteInfo.rss.site_url);
file.meta.url = url.pathname = path.join(siteCwd, file.meta.slug);
file.meta.fullurl = url.toString();
// file.meta.originalpath = path.relative(file.cwd, file.path);
const { images, titlecard } = await getFileData(cwd, siteCwd);
file.meta.images = images;
file.meta.titlecard = titlecard;
flags.add(titlecard ? 'has-titlecard' : 'no-titlecard');
if (file.meta['no-title']) {
flags.add('hide-title');
} else if (file.meta.title || file.meta.description) {
flags.add('show-title');
} else {
flags.add('hide-title');
}
flags.add(file.meta.title ? 'has-title' : 'no-title');
flags.add(file.meta.subtitle ? 'has-subtitle' : 'no-subtitle');
flags.add(file.meta.description ? 'has-descrip' : 'no-descrip');
stream.push(file);
});
}
function parseTweets () {
const tweeturl = /https?:\/\/twitter\.com\/(?:#!\/)?(?:\w+)\/status(?:es)?\/(\d+)/i;
const tweetidcheck = /^\d+$/;
function parseTweetId (tweetid) {
// we can't trust an id that isn't a string
if (typeof tweetid !== 'string') return false;
const match = tweetid.match(tweeturl);
if (match) return match[1];
if (tweetid.match(tweetidcheck)) return tweetid;
return false;
}
return collect.list(async (files) => {
const twitterBackup = (await fs.readJson(path.join(ROOT, 'twitter-backup.json')).catch(() => {})) || {};
const twitterCache = (await fs.readJson(path.join(ROOT, 'twitter-cache.json')).catch(() => {})) || {};
const needed = [];
// first loop through all posts and gather + validate all tweet ids
for (const file of files) {
if (!file.meta.tweets && !file.meta.tweet) continue;
const tweets = [];
if (file.meta.tweet) {
file.meta.tweet = [ file.meta.tweet ].flat(1).map(parseTweetId);
tweets.push(...file.meta.tweet);
}
if (file.meta.tweets) {
file.meta.tweets = file.meta.tweets.map(parseTweetId);
tweets.push(...file.meta.tweets);
}
for (const id of tweets) {
if (!twitterCache[id]) {
needed.push(id);
}
}
file.meta.tweets = tweets;
}
// if we have tweets we need to add to the cache, do so
if (needed.length) {
log('Fetching tweets: ' + needed.join(', '));
const arriving = await Promise.all(chunk(uniq(needed), 99).map(twitter));
const loaded = [];
for (const tweet of arriving.flat(1)) {
if (!twitterBackup[tweet.id_str]) twitterBackup[tweet.id_str] = tweet;
twitterCache[tweet.id_str] = tweetparse(tweet);
loaded.push(tweet.id_str);
}
const absent = difference(needed, loaded);
for (const id of absent) {
if (twitterBackup[id]) {
log('Pulled tweet from backup ' + id);
twitterCache[id] = tweetparse(twitterBackup[id]);
continue;
}
log.error('Could not find tweet ' + id);
}
}
const media = [];
// now loop through posts and substitute the tweet data for the ids
for (const file of files) {
if (!file.meta.tweets) continue;
file.meta.tweets = file.meta.tweets.reduce((dict, tweetid) => {
const tweet = twitterCache[tweetid];
if (!tweet) log.error(`Tweet ${tweetid} is missing from the cache.`);
dict[tweetid] = tweet;
media.push( ...tweet.media );
return dict;
}, {});
}
await fs.writeFile(path.join(ROOT, 'twitter-media.json'), JSON.stringify(media, null, 2));
await fs.writeFile(path.join(ROOT, 'twitter-cache.json'), JSON.stringify(twitterCache, null, 2));
await fs.writeFile(path.join(ROOT, 'twitter-backup.json'), JSON.stringify(twitterBackup, null, 2));
return files;
});
}
/** **************************************************************************************************************** **/

View File

@ -3,10 +3,10 @@ const { series, parallel, watch } = require('gulp');
/** **************************************************************************************************************** **/
var { loadLayout, pages } = require('./contents');
var contentTask = series( loadLayout, pages );
exports.pages = series( loadLayout, pages );
exports.content = contentTask;
var content = require('./content');
exports.parse = content.parse;
exports.pages = content.write;
exports.content = series(content.parse, content.write);
var images = require('./imgflow');
exports.twimages = images.twitter;
@ -40,17 +40,15 @@ exports.cloudfront = cloudfront;
/** **************************************************************************************************************** **/
exports.new = require('./new');
var buildTask = series(
var prodBuildTask = series(
images.prod,
images.favicon.prod,
scssTask.prod,
jsTask.prod,
filesTask.prod,
loadLayout.prod,
pages.prod,
content.parse,
images.twitter.prod,
content.write.prod,
);
var devBuildTask = series(
@ -60,17 +58,17 @@ var devBuildTask = series(
scssTask,
jsTask,
filesTask,
content.parse,
),
loadLayout,
pages,
content.write,
images.twitter,
);
exports.dev = devBuildTask;
exports.prod = buildTask;
exports.prod = prodBuildTask;
exports.publish = series(
cleanTask,
buildTask,
prodBuildTask,
pushToProd,
cloudfront.prod,
);
@ -83,7 +81,7 @@ function watcher () {
watch([
'pages/**/*.{md,hbs,html}',
'templates/*.{md,hbs,html}',
], series(contentTask, images.twitter));
], series(content.parse, images.twitter, content.write));
watch('page/**/*.{jpeg,jpg,png,gif}', images);
@ -105,8 +103,8 @@ function server () {
}
exports.watch = series(contentTask, watcher);
exports.uat = series(cleanTask, buildTask, server);
exports.watch = series(series(content.parse, images.twitter, content.write), watcher);
exports.uat = series(cleanTask, prodBuildTask, server);
/** **************************************************************************************************************** **/

506
package-lock.json generated
View File

@ -721,12 +721,6 @@
"integrity": "sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw==",
"dev": true
},
"array-uniq": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/array-uniq/-/array-uniq-1.0.3.tgz",
"integrity": "sha1-r2rId6Jcx/dOBYiUdThY39sk/bY=",
"dev": true
},
"array-unique": {
"version": "0.3.2",
"resolved": "https://registry.npmjs.org/array-unique/-/array-unique-0.3.2.tgz",
@ -833,9 +827,9 @@
}
},
"aws-sdk": {
"version": "2.616.0",
"resolved": "https://registry.npmjs.org/aws-sdk/-/aws-sdk-2.616.0.tgz",
"integrity": "sha512-jvmUn5WgL7EQz3e40tDpmCQA2RlchMZkxp/yVOYv4eKVrW5Mxz4QVnPqIWXutK6Ml3C3/DBMR0uIQybztvSrGA==",
"version": "2.624.0",
"resolved": "https://registry.npmjs.org/aws-sdk/-/aws-sdk-2.624.0.tgz",
"integrity": "sha512-6MhbdND7A5lEBiNSZ/HLwhKgrysmwTy6C47H7vfuVnY25hDkIND3C0PLqeRyskUqxv0RqsiAB4kqiMtpE08IGA==",
"dev": true,
"requires": {
"buffer": "4.9.1",
@ -986,12 +980,6 @@
"tweetnacl": "^0.14.3"
}
},
"beeper": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/beeper/-/beeper-1.1.1.tgz",
"integrity": "sha1-5tXqjF2tABMEpwsiY4RH9pyy+Ak=",
"dev": true
},
"binary-extensions": {
"version": "1.13.1",
"resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-1.13.1.tgz",
@ -1238,41 +1226,6 @@
"integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==",
"dev": true
},
"bufferstreams": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/bufferstreams/-/bufferstreams-1.0.1.tgz",
"integrity": "sha1-z7GtlWjTujz+k1upq92VLeiKqyo=",
"dev": true,
"requires": {
"readable-stream": "^1.0.33"
},
"dependencies": {
"isarray": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz",
"integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=",
"dev": true
},
"readable-stream": {
"version": "1.1.14",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz",
"integrity": "sha1-fPTFTvZI44EwhMY23SB54WbAgdk=",
"dev": true,
"requires": {
"core-util-is": "~1.0.0",
"inherits": "~2.0.1",
"isarray": "0.0.1",
"string_decoder": "~0.10.x"
}
},
"string_decoder": {
"version": "0.10.31",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz",
"integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=",
"dev": true
}
}
},
"builtin-modules": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-3.1.0.tgz",
@ -1286,19 +1239,17 @@
"dev": true
},
"cacache": {
"version": "14.0.0",
"resolved": "https://registry.npmjs.org/cacache/-/cacache-14.0.0.tgz",
"integrity": "sha512-+Nr/BnA/tjAUXza9gH8F+FSP+1HvWqCKt4c95dQr4EDVJVafbzmPZpLKCkLYexs6vSd2B/1TOXrAoNnqVPfvRA==",
"version": "15.0.0",
"resolved": "https://registry.npmjs.org/cacache/-/cacache-15.0.0.tgz",
"integrity": "sha512-L0JpXHhplbJSiDGzyJJnJCTL7er7NzbBgxzVqLswEb4bO91Zbv17OUMuUeu/q0ZwKn3V+1HM4wb9tO4eVE/K8g==",
"dev": true,
"requires": {
"chownr": "^1.1.2",
"figgy-pudding": "^3.5.1",
"fs-minipass": "^2.0.0",
"glob": "^7.1.4",
"graceful-fs": "^4.2.2",
"infer-owner": "^1.0.4",
"lru-cache": "^5.1.1",
"minipass": "^3.0.0",
"minipass": "^3.1.1",
"minipass-collect": "^1.0.2",
"minipass-flush": "^1.0.5",
"minipass-pipeline": "^1.2.2",
@ -1307,8 +1258,8 @@
"p-map": "^3.0.0",
"promise-inflight": "^1.0.1",
"rimraf": "^2.7.1",
"ssri": "^7.0.0",
"tar": "^6.0.0",
"ssri": "^8.0.0",
"tar": "^6.0.1",
"unique-filename": "^1.1.1"
},
"dependencies": {
@ -2077,12 +2028,6 @@
"integrity": "sha512-khbFLu/MlzLjEzy9Gh8oY1hNt/Dvxw3J6Rbc28cVoYWQaC1S3YI4xwkF9ZWcjDLscbZlY9hISMr66RFzZagLsA==",
"dev": true
},
"dateformat": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/dateformat/-/dateformat-2.2.0.tgz",
"integrity": "sha1-QGXiATz5+5Ft39gu+1Bq1MZ2kGI=",
"dev": true
},
"debug": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz",
@ -2299,41 +2244,6 @@
}
}
},
"duplexer2": {
"version": "0.0.2",
"resolved": "https://registry.npmjs.org/duplexer2/-/duplexer2-0.0.2.tgz",
"integrity": "sha1-xhTc9n4vsUmVqRcR5aYX6KYKMds=",
"dev": true,
"requires": {
"readable-stream": "~1.1.9"
},
"dependencies": {
"isarray": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz",
"integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=",
"dev": true
},
"readable-stream": {
"version": "1.1.14",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz",
"integrity": "sha1-fPTFTvZI44EwhMY23SB54WbAgdk=",
"dev": true,
"requires": {
"core-util-is": "~1.0.0",
"inherits": "~2.0.1",
"isarray": "0.0.1",
"string_decoder": "~0.10.x"
}
},
"string_decoder": {
"version": "0.10.31",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz",
"integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=",
"dev": true
}
}
},
"duplexify": {
"version": "3.7.1",
"resolved": "https://registry.npmjs.org/duplexify/-/duplexify-3.7.1.tgz",
@ -3073,12 +2983,6 @@
"integrity": "sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc=",
"dev": true
},
"figgy-pudding": {
"version": "3.5.1",
"resolved": "https://registry.npmjs.org/figgy-pudding/-/figgy-pudding-3.5.1.tgz",
"integrity": "sha512-vNKxJHTEKNThjfrdJwHc7brvM6eVevuO5nTj6ez8ZQ1qbXTvGthucRF7S4vf2cr71QVnT70V34v0S1DyQsti0w==",
"dev": true
},
"figures": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/figures/-/figures-3.1.0.tgz",
@ -3371,12 +3275,12 @@
"dev": true
},
"front-matter": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/front-matter/-/front-matter-2.3.0.tgz",
"integrity": "sha1-cgOviWzjV+4E4qpFFp6pHtf2dQQ=",
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/front-matter/-/front-matter-3.1.0.tgz",
"integrity": "sha512-RFEK8N6waWTdwBZOPNEtvwMjZ/hUfpwXkYUYkmmOhQGdhSulXhWrFwiUhdhkduLDiIwbROl/faF1X/PC/GGRMw==",
"dev": true,
"requires": {
"js-yaml": "^3.10.0"
"js-yaml": "^3.13.1"
}
},
"fs-extra": {
@ -4391,24 +4295,22 @@
}
},
"gulp-awspublish": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/gulp-awspublish/-/gulp-awspublish-4.0.1.tgz",
"integrity": "sha512-lTS0rbCoKV0Ra9PHC5/g0Af8ydWktfpuAIgz78elKGP0OemvT/CaER8zY2/TeFvozkpXe5OOcdZ7dmHvBAJIIA==",
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/gulp-awspublish/-/gulp-awspublish-4.1.1.tgz",
"integrity": "sha512-TsdDssQBdLS2kaF8mJ2ETstqF0oyAe1vqDRmdBxIEP9KfVwMs8+Fr3pbcFXCFZKZc7jUK7hdUUjrANI7fzCqqQ==",
"dev": true,
"requires": {
"ansi-colors": "^4.1.1",
"aws-sdk": "^2.389.0",
"clone": "^2.1.2",
"fancy-log": "^1.3.3",
"lodash.chunk": "^4.2.0",
"mime-types": "^2.1.21",
"pad-component": "^0.0.1",
"pascal-case": "^2.0.0",
"plugin-error": "^1.0.1",
"pumpify": "^2.0.1",
"through2": "^3.0.1",
"vinyl": "^2.2.0",
"xml-nodes": "^0.1.5",
"xml-objects": "^1.0.1"
"vinyl": "^2.2.0"
},
"dependencies": {
"ansi-colors": {
@ -4416,50 +4318,6 @@
"resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-4.1.1.tgz",
"integrity": "sha512-JoX0apGbHaUJBNl6yF+p6JAFYZ666/hhCGKN5t9QFjbJQKUU/g8MNbFDbvfrgKXvI1QpZplPOnwIo99lX/AAmA==",
"dev": true
},
"duplexify": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/duplexify/-/duplexify-4.1.1.tgz",
"integrity": "sha512-DY3xVEmVHTv1wSzKNbwoU6nVjzI369Y6sPoqfYr0/xlx3IdX2n94xIszTcjPO8W8ZIv0Wb0PXNcjuZyT4wiICA==",
"dev": true,
"requires": {
"end-of-stream": "^1.4.1",
"inherits": "^2.0.3",
"readable-stream": "^3.1.1",
"stream-shift": "^1.0.0"
}
},
"pump": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz",
"integrity": "sha512-LwZy+p3SFs1Pytd/jYct4wpv49HiYCqd9Rlc5ZVdk0V+8Yzv6jR5Blk3TRmPL1ft69TxP0IMZGJ+WPFU2BFhww==",
"dev": true,
"requires": {
"end-of-stream": "^1.1.0",
"once": "^1.3.1"
}
},
"pumpify": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/pumpify/-/pumpify-2.0.1.tgz",
"integrity": "sha512-m7KOje7jZxrmutanlkS1daj1dS6z6BgslzOXmcSEpIlCxM3VJH7lG5QLeck/6hgF6F4crFf01UtQmNsJfweTAw==",
"dev": true,
"requires": {
"duplexify": "^4.1.1",
"inherits": "^2.0.3",
"pump": "^3.0.0"
}
},
"readable-stream": {
"version": "3.5.0",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.5.0.tgz",
"integrity": "sha512-gSz026xs2LfxBPudDuI41V1lka8cxg64E66SGe78zJlsUofOg/yqwezdIcdfwik6B4h8LFmWPA9ef9X3FiNFLA==",
"dev": true,
"requires": {
"inherits": "^2.0.3",
"string_decoder": "^1.1.1",
"util-deprecate": "^1.0.1"
}
}
}
},
@ -4710,12 +4568,6 @@
}
}
},
"gulp-collect": {
"version": "0.1.0",
"resolved": "https://registry.npmjs.org/gulp-collect/-/gulp-collect-0.1.0.tgz",
"integrity": "sha1-PPlIjk9Xn3OauiGcdnbc1aoLJ24=",
"dev": true
},
"gulp-concat": {
"version": "2.6.1",
"resolved": "https://registry.npmjs.org/gulp-concat/-/gulp-concat-2.6.1.tgz",
@ -4750,20 +4602,6 @@
"streamfilter": "^3.0.0"
}
},
"gulp-front-matter": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/gulp-front-matter/-/gulp-front-matter-1.3.0.tgz",
"integrity": "sha1-XuRm+/r7M0ILzV4CZ7toGURKsG0=",
"dev": true,
"requires": {
"front-matter": "^2.0.0",
"gulp-util": "^3.0.6",
"object-path": "^0.9.2",
"readable-stream": "^2.0.3",
"tryit": "^1.0.1",
"vinyl-bufferstream": "^1.0.1"
}
},
"gulp-minify": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/gulp-minify/-/gulp-minify-3.1.0.tgz",
@ -4930,125 +4768,6 @@
}
}
},
"gulp-util": {
"version": "3.0.8",
"resolved": "https://registry.npmjs.org/gulp-util/-/gulp-util-3.0.8.tgz",
"integrity": "sha1-AFTh50RQLifATBh8PsxQXdVLu08=",
"dev": true,
"requires": {
"array-differ": "^1.0.0",
"array-uniq": "^1.0.2",
"beeper": "^1.0.0",
"chalk": "^1.0.0",
"dateformat": "^2.0.0",
"fancy-log": "^1.1.0",
"gulplog": "^1.0.0",
"has-gulplog": "^0.1.0",
"lodash._reescape": "^3.0.0",
"lodash._reevaluate": "^3.0.0",
"lodash._reinterpolate": "^3.0.0",
"lodash.template": "^3.0.0",
"minimist": "^1.1.0",
"multipipe": "^0.1.2",
"object-assign": "^3.0.0",
"replace-ext": "0.0.1",
"through2": "^2.0.0",
"vinyl": "^0.5.0"
},
"dependencies": {
"ansi-regex": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz",
"integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=",
"dev": true
},
"ansi-styles": {
"version": "2.2.1",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-2.2.1.tgz",
"integrity": "sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4=",
"dev": true
},
"array-differ": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/array-differ/-/array-differ-1.0.0.tgz",
"integrity": "sha1-7/UuN1gknTO+QCuLuOVkuytdQDE=",
"dev": true
},
"chalk": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz",
"integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=",
"dev": true,
"requires": {
"ansi-styles": "^2.2.1",
"escape-string-regexp": "^1.0.2",
"has-ansi": "^2.0.0",
"strip-ansi": "^3.0.0",
"supports-color": "^2.0.0"
}
},
"clone": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/clone/-/clone-1.0.4.tgz",
"integrity": "sha1-2jCcwmPfFZlMaIypAheco8fNfH4=",
"dev": true
},
"clone-stats": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/clone-stats/-/clone-stats-0.0.1.tgz",
"integrity": "sha1-uI+UqCzzi4eR1YBG6kAprYjKmdE=",
"dev": true
},
"object-assign": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/object-assign/-/object-assign-3.0.0.tgz",
"integrity": "sha1-m+3VygiXlJvKR+f/QIBi1Un1h/I=",
"dev": true
},
"replace-ext": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/replace-ext/-/replace-ext-0.0.1.tgz",
"integrity": "sha1-KbvZIHinOfC8zitO5B6DeVNSKSQ=",
"dev": true
},
"strip-ansi": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz",
"integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=",
"dev": true,
"requires": {
"ansi-regex": "^2.0.0"
}
},
"supports-color": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz",
"integrity": "sha1-U10EXOa2Nj+kARcIRimZXp3zJMc=",
"dev": true
},
"through2": {
"version": "2.0.5",
"resolved": "https://registry.npmjs.org/through2/-/through2-2.0.5.tgz",
"integrity": "sha512-/mrRod8xqpA+IHSLyGCQ2s8SPHiCDEeQJSep1jqLYeEUClOFG2Qsh+4FU6G9VeqpZnGW/Su8LQGc4YKni5rYSQ==",
"dev": true,
"requires": {
"readable-stream": "~2.3.6",
"xtend": "~4.0.1"
}
},
"vinyl": {
"version": "0.5.3",
"resolved": "https://registry.npmjs.org/vinyl/-/vinyl-0.5.3.tgz",
"integrity": "sha1-sEVbOPxeDPMNQyUTLkYZcMIJHN4=",
"dev": true,
"requires": {
"clone": "^1.0.0",
"clone-stats": "^0.0.1",
"replace-ext": "0.0.1"
}
}
}
},
"gulplog": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/gulplog/-/gulplog-1.0.0.tgz",
@ -5126,15 +4845,6 @@
"integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=",
"dev": true
},
"has-gulplog": {
"version": "0.1.0",
"resolved": "https://registry.npmjs.org/has-gulplog/-/has-gulplog-0.1.0.tgz",
"integrity": "sha1-ZBTIKRNpfaUVkDl9r7EvIpZ4Ec4=",
"dev": true,
"requires": {
"sparkles": "^1.0.0"
}
},
"has-symbols": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.1.tgz",
@ -6142,143 +5852,30 @@
"integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==",
"dev": true
},
"lodash._basecopy": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/lodash._basecopy/-/lodash._basecopy-3.0.1.tgz",
"integrity": "sha1-jaDmqHbPNEwK2KVIghEd08XHyjY=",
"dev": true
},
"lodash._basetostring": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/lodash._basetostring/-/lodash._basetostring-3.0.1.tgz",
"integrity": "sha1-0YYdh3+CSlL2aYMtyvPuFVZqB9U=",
"dev": true
},
"lodash._basevalues": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/lodash._basevalues/-/lodash._basevalues-3.0.0.tgz",
"integrity": "sha1-W3dXYoAr3j0yl1A+JjAIIP32Ybc=",
"dev": true
},
"lodash._getnative": {
"version": "3.9.1",
"resolved": "https://registry.npmjs.org/lodash._getnative/-/lodash._getnative-3.9.1.tgz",
"integrity": "sha1-VwvH3t5G1hzc3mh9ZdPuy6o6r/U=",
"dev": true
},
"lodash._isiterateecall": {
"version": "3.0.9",
"resolved": "https://registry.npmjs.org/lodash._isiterateecall/-/lodash._isiterateecall-3.0.9.tgz",
"integrity": "sha1-UgOte6Ql+uhCRg5pbbnPPmqsBXw=",
"dev": true
},
"lodash._reescape": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/lodash._reescape/-/lodash._reescape-3.0.0.tgz",
"integrity": "sha1-Kx1vXf4HyKNVdT5fJ/rH8c3hYWo=",
"dev": true
},
"lodash._reevaluate": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/lodash._reevaluate/-/lodash._reevaluate-3.0.0.tgz",
"integrity": "sha1-WLx0xAZklTrgsSTYBpltrKQx4u0=",
"dev": true
},
"lodash._reinterpolate": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/lodash._reinterpolate/-/lodash._reinterpolate-3.0.0.tgz",
"integrity": "sha1-DM8tiRZq8Ds2Y8eWU4t1rG4RTZ0=",
"dev": true
},
"lodash._root": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/lodash._root/-/lodash._root-3.0.1.tgz",
"integrity": "sha1-+6HEUkwZ7ppfgTa0YJ8BfPTe1pI=",
"dev": true
},
"lodash.camelcase": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/lodash.camelcase/-/lodash.camelcase-4.3.0.tgz",
"integrity": "sha1-soqmKIorn8ZRA1x3EfZathkDMaY=",
"dev": true
},
"lodash.chunk": {
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/lodash.chunk/-/lodash.chunk-4.2.0.tgz",
"integrity": "sha1-ZuXOH3btJ7QwPYxlEujRIW6BBrw=",
"dev": true
},
"lodash.clonedeep": {
"version": "4.5.0",
"resolved": "https://registry.npmjs.org/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz",
"integrity": "sha1-4j8/nE+Pvd6HJSnBBxhXoIblzO8=",
"dev": true
},
"lodash.escape": {
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/lodash.escape/-/lodash.escape-3.2.0.tgz",
"integrity": "sha1-mV7g3BjBtIzJLv+ucaEKq1tIdpg=",
"dev": true,
"requires": {
"lodash._root": "^3.0.0"
}
},
"lodash.isarguments": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/lodash.isarguments/-/lodash.isarguments-3.1.0.tgz",
"integrity": "sha1-L1c9hcaiQon/AGY7SRwdM4/zRYo=",
"dev": true
},
"lodash.isarray": {
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/lodash.isarray/-/lodash.isarray-3.0.4.tgz",
"integrity": "sha1-eeTriMNqgSKvhvhEqpvNhRtfu1U=",
"dev": true
},
"lodash.isplainobject": {
"version": "4.0.6",
"resolved": "https://registry.npmjs.org/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz",
"integrity": "sha1-fFJqUtibRcRcxpC4gWO+BJf1UMs=",
"dev": true
},
"lodash.keys": {
"version": "3.1.2",
"resolved": "https://registry.npmjs.org/lodash.keys/-/lodash.keys-3.1.2.tgz",
"integrity": "sha1-TbwEcrFWvlCgsoaFXRvQsMZWCYo=",
"dev": true,
"requires": {
"lodash._getnative": "^3.0.0",
"lodash.isarguments": "^3.0.0",
"lodash.isarray": "^3.0.0"
}
},
"lodash.restparam": {
"version": "3.6.1",
"resolved": "https://registry.npmjs.org/lodash.restparam/-/lodash.restparam-3.6.1.tgz",
"integrity": "sha1-k2pOMJ7zMKdkXtQUWYbIWuWyCAU=",
"dev": true
},
"lodash.template": {
"version": "3.6.2",
"resolved": "https://registry.npmjs.org/lodash.template/-/lodash.template-3.6.2.tgz",
"integrity": "sha1-+M3sxhaaJVvpCYrosMU9N4kx0U8=",
"dev": true,
"requires": {
"lodash._basecopy": "^3.0.0",
"lodash._basetostring": "^3.0.0",
"lodash._basevalues": "^3.0.0",
"lodash._isiterateecall": "^3.0.0",
"lodash._reinterpolate": "^3.0.0",
"lodash.escape": "^3.0.0",
"lodash.keys": "^3.0.0",
"lodash.restparam": "^3.0.0",
"lodash.templatesettings": "^3.0.0"
}
},
"lodash.templatesettings": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/lodash.templatesettings/-/lodash.templatesettings-3.1.1.tgz",
"integrity": "sha1-+zB4RHU7Zrnxr6VOJix0UwfbqOU=",
"dev": true,
"requires": {
"lodash._reinterpolate": "^3.0.0",
"lodash.escape": "^3.0.0"
}
},
"lodash.trim": {
"version": "4.5.1",
"resolved": "https://registry.npmjs.org/lodash.trim/-/lodash.trim-4.5.1.tgz",
@ -6342,14 +5939,14 @@
}
},
"make-fetch-happen": {
"version": "7.1.1",
"resolved": "https://registry.npmjs.org/make-fetch-happen/-/make-fetch-happen-7.1.1.tgz",
"integrity": "sha512-7fNjiOXNZhNGQzG5P15nU97aZQtzPU2GVgVd7pnqnl5gnpLzMAD8bAe5YG4iW2s0PTqaZy9xGv4Wfqe872kRNQ==",
"version": "8.0.1",
"resolved": "https://registry.npmjs.org/make-fetch-happen/-/make-fetch-happen-8.0.1.tgz",
"integrity": "sha512-oiK8xz6+IxaPqmOCW+rmlH922RTZ+fi4TAULGRih8ryqIju0x6WriDR3smm7Z+8NZRxDIK/iDLM096F/gLfiWg==",
"dev": true,
"requires": {
"agentkeepalive": "^4.1.0",
"cacache": "^14.0.0",
"http-cache-semantics": "^4.0.3",
"cacache": "^15.0.0",
"http-cache-semantics": "^4.0.4",
"http-proxy-agent": "^3.0.0",
"https-proxy-agent": "^4.0.0",
"is-lambda": "^1.0.1",
@ -6361,7 +5958,7 @@
"minipass-pipeline": "^1.2.2",
"promise-retry": "^1.1.1",
"socks-proxy-agent": "^4.0.0",
"ssri": "^7.0.1"
"ssri": "^8.0.0"
},
"dependencies": {
"lru-cache": {
@ -6802,15 +6399,6 @@
"minimatch": "^3.0.4"
}
},
"multipipe": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/multipipe/-/multipipe-0.1.2.tgz",
"integrity": "sha1-Ko8t33Du1WTf8tV/HhoTfZ8FB4s=",
"dev": true,
"requires": {
"duplexer2": "0.0.2"
}
},
"mute-stdout": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/mute-stdout/-/mute-stdout-1.0.1.tgz",
@ -7185,12 +6773,6 @@
"integrity": "sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==",
"dev": true
},
"object-path": {
"version": "0.9.2",
"resolved": "https://registry.npmjs.org/object-path/-/object-path-0.9.2.tgz",
"integrity": "sha1-D9mnT8X60a45aLWGvaXGMr1sBaU=",
"dev": true
},
"object-visit": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/object-visit/-/object-visit-1.0.1.tgz",
@ -8269,9 +7851,9 @@
}
},
"rollup": {
"version": "1.31.0",
"resolved": "https://registry.npmjs.org/rollup/-/rollup-1.31.0.tgz",
"integrity": "sha512-9C6ovSyNeEwvuRuUUmsTpJcXac1AwSL1a3x+O5lpmQKZqi5mmrjauLeqIjvREC+yNRR8fPdzByojDng+af3nVw==",
"version": "1.31.1",
"resolved": "https://registry.npmjs.org/rollup/-/rollup-1.31.1.tgz",
"integrity": "sha512-2JREN1YdrS/kpPzEd33ZjtuNbOuBC3ePfuZBdKEybvqcEcszW1ckyVqzcEiEe0nE8sqHK+pbJg+PsAgRJ8+1dg==",
"dev": true,
"requires": {
"@types/estree": "*",
@ -9057,12 +8639,11 @@
}
},
"ssri": {
"version": "7.1.0",
"resolved": "https://registry.npmjs.org/ssri/-/ssri-7.1.0.tgz",
"integrity": "sha512-77/WrDZUWocK0mvA5NTRQyveUf+wsrIc6vyrxpS8tVvYBcX215QbafrJR3KtkpskIzoFLqqNuuYQvxaMjXJ/0g==",
"version": "8.0.0",
"resolved": "https://registry.npmjs.org/ssri/-/ssri-8.0.0.tgz",
"integrity": "sha512-aq/pz989nxVYwn16Tsbj1TqFpD5LLrQxHf5zaHuieFV+R0Bbr4y8qUsOA45hXT/N4/9UNXTarBjnjVmjSOVaAA==",
"dev": true,
"requires": {
"figgy-pudding": "^3.5.1",
"minipass": "^3.1.1"
}
},
@ -9643,12 +9224,6 @@
"integrity": "sha512-em3E3SUDONOjTBcZ36DTm3RvDded3IRU9rX32oHwwXNt3rJD5MVaFlJTQvs8tJoHRoeYP36OuQ1eL/Q7bNEWIQ==",
"dev": true
},
"tryit": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/tryit/-/tryit-1.0.3.tgz",
"integrity": "sha1-OTvnMKlEb9Hq1tpZoBQwjzbCics=",
"dev": true
},
"tslib": {
"version": "1.10.0",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-1.10.0.tgz",
@ -10083,15 +9658,6 @@
"replace-ext": "^1.0.0"
}
},
"vinyl-bufferstream": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/vinyl-bufferstream/-/vinyl-bufferstream-1.0.1.tgz",
"integrity": "sha1-BTeGn1gO/6TKRay0dXnkuf5jCBo=",
"dev": true,
"requires": {
"bufferstreams": "1.0.1"
}
},
"vinyl-file": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/vinyl-file/-/vinyl-file-3.0.0.tgz",

View File

@ -12,6 +12,7 @@
"siteInfo": {
"title": "That's Gender Dysphoria, FYI",
"domain": "genderdysphoria.fyi",
"siteUrl": "https://genderdysphoria.fyi",
"rss": {
"title": "That's Gender Dysphoria, FYI",
"feed_url": "https://genderdysphoria.fyi/atom.xml",
@ -22,7 +23,7 @@
"license": "MIT",
"devDependencies": {
"autoprefixer": "~9.7.4",
"aws-sdk": "~2.616.0",
"aws-sdk": "~2.624.0",
"backbone": "~1.4.0",
"bluebird": "~3.7.2",
"bootstrap": "~4.4.1",
@ -36,20 +37,19 @@
"express": "~4.17.1",
"fancy-log": "~1.3.3",
"forever": "~2.0.0",
"front-matter": "~3.1.0",
"fs-extra": "~8.1.0",
"glob": "~7.1.6",
"gm": "~1.23.1",
"gulp": "~4.0.2",
"gulp-awspublish": "~4.0.1",
"gulp-awspublish": "~4.1.1",
"gulp-awspublish-router": "~0.2.0",
"gulp-better-rollup": "~4.0.1",
"gulp-changed": "~4.0.2",
"gulp-clean": "~0.4.0",
"gulp-cloudfront-invalidate-aws-publish": "~1.0.0",
"gulp-collect": "~0.1.0",
"gulp-concat": "~2.6.1",
"gulp-filter": "~6.0.0",
"gulp-front-matter": "~1.3.0",
"gulp-minify": "~3.1.0",
"gulp-postcss": "~8.0.0",
"gulp-rev": "~9.0.0",
@ -61,7 +61,7 @@
"jquery": "~3.4.1",
"lodash": "~4.17.15",
"magnific-popup": "~1.1.0",
"make-fetch-happen": "~7.1.1",
"make-fetch-happen": "~8.0.1",
"markdown-it": "~10.0.0",
"markdown-it-anchor": "~5.2.5",
"memoizepromise": "~2.0.0",
@ -74,7 +74,7 @@
"popper.js": "~1.16.0",
"rev-hash": "~3.0.0",
"rev-path": "~2.0.0",
"rollup": "~1.31.0",
"rollup": "~1.31.1",
"rollup-plugin-alias": "~2.2.0",
"rollup-plugin-commonjs": "~10.1.0",
"rollup-plugin-json": "~4.0.0",

View File

@ -63,7 +63,7 @@
<div class="top-nav">
<ul class="top-nav-inner">
<!-- <li><a href="/glossary" class="top-nav-item">Glossary</a></li> -->
<li><a href="/gdb/" class="top-nav-item dropdown-toggle" id="nav-gdb" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">The Gender Dysphoria Bible</a>{{inject '/pages/gdb/_menu'}}</li>
<li><a href="/gdb/" class="top-nav-item dropdown-toggle" id="nav-gdb" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">The Gender Dysphoria Bible</a>{{import '/pages/gdb/_menu'}}</li>
<!-- <li><a href="/guides/" class="top-nav-item">Guides</a></li> -->
<!-- <li class="break"></li> -->
<li><a href="https://github.com/GenderDysphoria/GenderDysphoria.fyi" class="top-nav-item">{{icon 'brands/github'}}</a></li>

View File

@ -24,7 +24,7 @@
{{#content "body"}}
<article class="{{#each classes}}{{this}} {{/each}}markup">
<div class="post-content">{{{this.contents}}}</div>
<div class="post-content">{{{contents}}}</div>
</article>
{{/content}}