You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
869 B
32 lines
869 B
2 years ago
|
'use strict';
|
||
|
|
||
|
const { Schema } = require('warehouse');
|
||
|
const { join } = require('path');
|
||
|
|
||
|
module.exports = ctx => {
|
||
|
const PostAsset = new Schema({
|
||
|
_id: {type: String, required: true},
|
||
|
slug: {type: String, required: true},
|
||
|
modified: {type: Boolean, default: true},
|
||
|
post: {type: Schema.Types.CUID, ref: 'Post'},
|
||
|
renderable: {type: Boolean, default: true}
|
||
|
});
|
||
|
|
||
|
PostAsset.virtual('path').get(function() {
|
||
|
const Post = ctx.model('Post');
|
||
|
const post = Post.findById(this.post);
|
||
|
if (!post) return;
|
||
|
|
||
|
// PostAsset.path is file path relative to `public_dir`
|
||
|
// no need to urlescape, #1562
|
||
|
// strip /\.html?$/ extensions on permalink, #2134
|
||
|
return join(post.path.replace(/\.html?$/, ''), this.slug);
|
||
|
});
|
||
|
|
||
|
PostAsset.virtual('source').get(function() {
|
||
|
return join(ctx.base_dir, this._id);
|
||
|
});
|
||
|
|
||
|
return PostAsset;
|
||
|
};
|