53 lines
1.2 KiB
JavaScript
53 lines
1.2 KiB
JavaScript
import mongoose from "mongoose";
|
|
|
|
const articleSchema = new mongoose.Schema(
|
|
{
|
|
slug: {
|
|
type: String,
|
|
required: [true, "Slug is required"],
|
|
unique: true,
|
|
lowercase: true,
|
|
trim: true,
|
|
index: true,
|
|
},
|
|
title: {
|
|
type: String,
|
|
required: [true, "Title is required"],
|
|
trim: true,
|
|
},
|
|
content: {
|
|
type: String,
|
|
default: "",
|
|
},
|
|
tags: {
|
|
type: [String],
|
|
default: [],
|
|
},
|
|
// Language this version of the article is written in, as a lowercase
|
|
// ISO 639-1 code ("en", "fr", "de", ...). Defaults to English.
|
|
language: {
|
|
type: String,
|
|
default: "en",
|
|
lowercase: true,
|
|
trim: true,
|
|
},
|
|
// For a translation: the identity of the article it translates — the
|
|
// canonical (original) version's slug. Null on the canonical document.
|
|
baseSlug: {
|
|
type: String,
|
|
default: null,
|
|
lowercase: true,
|
|
trim: true,
|
|
index: true,
|
|
},
|
|
},
|
|
{ timestamps: true }
|
|
);
|
|
|
|
// Text index for search across title and tags
|
|
articleSchema.index({ title: "text", tags: "text" });
|
|
|
|
const Article = mongoose.model("Article", articleSchema);
|
|
|
|
export default Article;
|