UNPKG

meblog

Version:

A simple blog engine for personal blogging

57 lines (56 loc) 1.67 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Post = void 0; const tslib_1 = require("tslib"); const moment_1 = tslib_1.__importDefault(require("moment")); const gulplog_1 = tslib_1.__importDefault(require("gulplog")); const ansi_colors_1 = tslib_1.__importDefault(require("ansi-colors")); const StringUtils_1 = tslib_1.__importDefault(require("../util/StringUtils")); class Post { title; slug; publishedAt; tags; excerpt; body; markdown; layout; url; relativeUrl; language; constructor(post) { this.copyInto(post); } copyInto(post) { if (!post) { return; } this.convertPublishedDate(post); post.tags = StringUtils_1.default.collectTags(post.tags); if (!post.layout) { post.layout = 'post'; } Object.assign(this, post); } convertPublishedDate(post) { if (post.publishedAt instanceof Date) { return; } const date = new Date(String(post.publishedAt)); if (isNaN(date.getTime())) { gulplog_1.default.info(`${ansi_colors_1.default.red('Invalid date')}\ ${ansi_colors_1.default.green(post.publishedAt)} from post ${ansi_colors_1.default.green(post.title)},\ this post will be ignore from showing`); post.publishedAt = null; return; } post.publishedAt = date; } get publishedMonth() { return moment_1.default(this.publishedAt).format('YYYY/MM'); } get publishedYear() { return moment_1.default(this.publishedAt).format('YYYY'); } } exports.Post = Post;