2020-02-29 16:27:55 -08:00
|
|
|
const glob = require('./lib/glob');
|
|
|
|
const { ROOT, KIND } = require('./resolve');
|
2020-04-07 10:33:06 -07:00
|
|
|
const { without } = require('lodash');
|
|
|
|
const Asset = require('./asset');
|
2020-02-29 16:27:55 -08:00
|
|
|
const Post = require('./post');
|
|
|
|
const Files = require('./files');
|
|
|
|
|
|
|
|
class PostFiles extends Files {
|
|
|
|
_kindMap () {
|
|
|
|
return {
|
|
|
|
[KIND.PAGE]: Post,
|
2020-04-07 10:33:06 -07:00
|
|
|
[KIND.ASSET]: PostAsset,
|
2020-02-29 16:27:55 -08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = exports = async function loadPublicFiles () {
|
|
|
|
return new PostFiles(await glob('posts/**/*', { cwd: ROOT, nodir: true }));
|
|
|
|
};
|
|
|
|
|
2020-04-07 10:33:06 -07:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|