Internalize PostAsset into Posts

This commit is contained in:
Jocelyn Badgley (Twipped) 2020-04-07 10:33:06 -07:00
parent 8796f52c9d
commit de4dfd765d
2 changed files with 15 additions and 20 deletions

View File

@ -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;
}
};

View File

@ -1,7 +1,7 @@
const glob = require('./lib/glob'); const glob = require('./lib/glob');
const { ROOT, KIND } = require('./resolve'); const { ROOT, KIND } = require('./resolve');
const File = require('./file'); const { without } = require('lodash');
const Asset = require('./post-asset'); const Asset = require('./asset');
const Post = require('./post'); const Post = require('./post');
const Files = require('./files'); const Files = require('./files');
@ -9,8 +9,7 @@ class PostFiles extends Files {
_kindMap () { _kindMap () {
return { return {
[KIND.PAGE]: Post, [KIND.PAGE]: Post,
[KIND.ASSET]: Asset, [KIND.ASSET]: PostAsset,
[KIND.OTHER]: File,
}; };
} }
} }
@ -19,3 +18,15 @@ module.exports = exports = async function loadPublicFiles () {
return new PostFiles(await glob('posts/**/*', { cwd: ROOT, nodir: true })); 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;
}
}