Spaces:
Sleeping
Sleeping
| const mongoose = require('mongoose'); | |
| const blogPostSchema = new mongoose.Schema( | |
| { | |
| title: { type: String, required: true }, | |
| slug: { type: String, required: true, lowercase: true }, | |
| body: { type: String, required: true }, | |
| author: { type: mongoose.Schema.Types.ObjectId, ref: 'Admin', required: true }, | |
| category: { type: String }, | |
| tags: [{ type: String }], | |
| featuredImage: { type: String }, | |
| publishDate: { type: Date }, | |
| status: { | |
| type: String, | |
| enum: ['draft', 'published', 'scheduled', 'archived'], | |
| default: 'draft', | |
| }, | |
| // SEO | |
| metaTitle: { type: String }, | |
| metaDescription: { type: String }, | |
| // Related | |
| relatedArticles: [{ type: mongoose.Schema.Types.ObjectId, ref: 'BlogPost' }], | |
| }, | |
| { timestamps: true } | |
| ); | |
| blogPostSchema.index({ slug: 1 }); | |
| blogPostSchema.index({ status: 1, publishDate: -1 }); | |
| blogPostSchema.index({ category: 1, tags: 1 }); | |
| module.exports = mongoose.model('BlogPost', blogPostSchema); | |