UX/UI improvements.
This commit is contained in:
parent
418d3cc402
commit
4e6f5d36b8
14 changed files with 1964 additions and 924 deletions
|
|
@ -187,20 +187,35 @@ const eventSchema = new mongoose.Schema({
|
|||
updatedAt: { type: Date, default: Date.now },
|
||||
});
|
||||
|
||||
// Generate slug from title
|
||||
function generateSlug(title) {
|
||||
return title
|
||||
// Generate slug from title and startDate
|
||||
function generateSlug(title, startDate) {
|
||||
const titleSlug = title
|
||||
.toLowerCase()
|
||||
.replace(/[^a-z0-9]+/g, "-")
|
||||
.replace(/^-+|-+$/g, "");
|
||||
|
||||
if (startDate) {
|
||||
const d = new Date(startDate);
|
||||
const year = d.getUTCFullYear();
|
||||
const month = String(d.getUTCMonth() + 1).padStart(2, "0");
|
||||
const day = String(d.getUTCDate()).padStart(2, "0");
|
||||
return `${year}-${month}-${day}-${titleSlug}`;
|
||||
}
|
||||
|
||||
return titleSlug;
|
||||
}
|
||||
|
||||
// Pre-save hook to generate slug
|
||||
eventSchema.pre("save", async function (next) {
|
||||
try {
|
||||
// Always generate slug if it doesn't exist or if title has changed
|
||||
if (!this.slug || this.isNew || this.isModified("title")) {
|
||||
let baseSlug = generateSlug(this.title);
|
||||
// Always generate slug if it doesn't exist or if title/startDate has changed
|
||||
if (
|
||||
!this.slug ||
|
||||
this.isNew ||
|
||||
this.isModified("title") ||
|
||||
this.isModified("startDate")
|
||||
) {
|
||||
let baseSlug = generateSlug(this.title, this.startDate);
|
||||
let slug = baseSlug;
|
||||
let counter = 1;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue