From de4dfd765d9ee4e5ba8f3230643a5cdbe819ee61 Mon Sep 17 00:00:00 2001 From: "Jocelyn Badgley (Twipped)" Date: Tue, 7 Apr 2020 10:33:06 -0700 Subject: [PATCH] Internalize PostAsset into Posts --- build/post-asset.js | 16 ---------------- build/posts.js | 19 +++++++++++++++---- 2 files changed, 15 insertions(+), 20 deletions(-) delete mode 100644 build/post-asset.js diff --git a/build/post-asset.js b/build/post-asset.js deleted file mode 100644 index 5a2a278..0000000 --- a/build/post-asset.js +++ /dev/null @@ -1,16 +0,0 @@ - -const { without } = require('lodash'); -const Asset = require('./asset'); - -const postmatch = /(\d{4}-\d\d-\d\d)\.\d{4}\.(\w+)/; - -module.exports = exports = class PostAsset extends Asset { - - _dir (dir) { - dir = dir.replace(postmatch, '$2').split('/'); - dir = without(dir, 'posts', '_images'); - dir.unshift('p'); - return dir; - } - -}; diff --git a/build/posts.js b/build/posts.js index 63b8d21..58cfa1f 100644 --- a/build/posts.js +++ b/build/posts.js @@ -1,7 +1,7 @@ const glob = require('./lib/glob'); const { ROOT, KIND } = require('./resolve'); -const File = require('./file'); -const Asset = require('./post-asset'); +const { without } = require('lodash'); +const Asset = require('./asset'); const Post = require('./post'); const Files = require('./files'); @@ -9,8 +9,7 @@ class PostFiles extends Files { _kindMap () { return { [KIND.PAGE]: Post, - [KIND.ASSET]: Asset, - [KIND.OTHER]: File, + [KIND.ASSET]: PostAsset, }; } } @@ -19,3 +18,15 @@ module.exports = exports = async function loadPublicFiles () { return new PostFiles(await glob('posts/**/*', { cwd: ROOT, nodir: true })); }; +const POSTMATCH = /(\d{4}-\d\d-\d\d)\.\d{4}\.(\w+)/; + +class PostAsset extends Asset { + + _dir (dir) { + dir = dir.replace(POSTMATCH, '$2').split('/'); + dir = without(dir, 'posts', '_images'); + dir.unshift('p'); + return dir; + } + +}