WeChatApps/models/article.js
2025-05-15 18:54:22 +08:00

23 lines
511 B
JavaScript

/**
* 文章数据模型
*/
class Article {
constructor(id, title, content, cover, summary, createTime) {
this.id = id;
this.title = title;
this.content = content;
this.cover = cover;
this.summary = summary || this.generateSummary(content);
this.createTime = createTime || new Date().getTime();
}
// 生成摘要
generateSummary(content) {
if (!content) return '';
return content.substring(0, 100).replace(/<[^>]+>/g, '') + '...';
}
}
module.exports = {
Article
}