let's slugifyyyy
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<template lang="pug">
|
||||
v-card.h-event.event
|
||||
nuxt-link(:to='`/event/${event.id}`')
|
||||
nuxt-link(:to='`/event/${event.slug || event.id}`')
|
||||
v-img.img(:src="`/media/thumb/${event.image_path || 'logo.svg' }`")
|
||||
v-icon.float-right.mr-1(v-if='event.parentId' color='success') mdi-repeat
|
||||
.title.p-name {{event.title}}
|
||||
@@ -43,4 +43,4 @@ export default {
|
||||
},
|
||||
computed: mapState(['settings'])
|
||||
}
|
||||
</script>
|
||||
</script>
|
||||
|
||||
@@ -67,6 +67,7 @@
|
||||
"prom-client": "^13.1.0",
|
||||
"sequelize": "^6.6.2",
|
||||
"sequelize-cli": "^6.2.0",
|
||||
"sequelize-slugify": "^1.5.0",
|
||||
"sharp": "^0.27.2",
|
||||
"sqlite3": "^5.0.2",
|
||||
"tiptap": "^1.32.0",
|
||||
|
||||
@@ -86,14 +86,21 @@ const eventController = {
|
||||
},
|
||||
|
||||
async get (req, res) {
|
||||
log.error('get')
|
||||
const format = req.params.format || 'json'
|
||||
const is_admin = req.user && req.user.is_admin
|
||||
const id = Number(req.params.event_id)
|
||||
const slug = req.params.event_id
|
||||
const id = Number(req.params.event_id) || -1
|
||||
console.error(slug)
|
||||
let event
|
||||
|
||||
try {
|
||||
event = await Event.findByPk(id, {
|
||||
event = await Event.findOne({
|
||||
where: {
|
||||
[Op.or]: {
|
||||
slug,
|
||||
id
|
||||
}
|
||||
},
|
||||
attributes: {
|
||||
exclude: ['createdAt', 'updatedAt', 'placeId']
|
||||
},
|
||||
@@ -112,6 +119,7 @@ const eventController = {
|
||||
order: [[Resource, 'id', 'DESC']]
|
||||
})
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
return res.sendStatus(400)
|
||||
}
|
||||
|
||||
@@ -119,6 +127,7 @@ const eventController = {
|
||||
return res.sendStatus(400)
|
||||
}
|
||||
|
||||
console.error('diocane')
|
||||
// get prev and next event
|
||||
const next = await Event.findOne({
|
||||
attributes: ['id'],
|
||||
@@ -446,7 +455,7 @@ const eventController = {
|
||||
const events = await Event.findAll({
|
||||
where,
|
||||
attributes: {
|
||||
exclude: ['slug', 'likes', 'boost', 'userId', 'is_visible', 'createdAt', 'updatedAt', 'description', 'resources']
|
||||
exclude: ['likes', 'boost', 'userId', 'is_visible', 'createdAt', 'updatedAt', 'description', 'resources']
|
||||
},
|
||||
order: ['start_datetime', Sequelize.literal('(SELECT COUNT("tagTag") FROM event_tags WHERE "tagTag" = tag) DESC')],
|
||||
include: [
|
||||
|
||||
@@ -3,6 +3,8 @@ const moment = require('dayjs')
|
||||
const htmlToText = require('html-to-text')
|
||||
|
||||
const { Model, DataTypes } = require('sequelize')
|
||||
const SequelizeSlugify = require('sequelize-slugify')
|
||||
|
||||
const sequelize = require('./index')
|
||||
|
||||
const Resource = require('./resource')
|
||||
@@ -26,7 +28,11 @@ Event.init({
|
||||
autoIncrement: true
|
||||
},
|
||||
title: DataTypes.STRING,
|
||||
slug: DataTypes.STRING,
|
||||
slug: {
|
||||
type: DataTypes.STRING,
|
||||
index: true,
|
||||
unique: true
|
||||
},
|
||||
description: DataTypes.TEXT,
|
||||
multidate: DataTypes.BOOLEAN,
|
||||
start_datetime: {
|
||||
@@ -62,6 +68,8 @@ Resource.belongsTo(Event)
|
||||
Event.hasMany(Event, { as: 'child', foreignKey: 'parentId' })
|
||||
Event.belongsTo(Event, { as: 'parent' })
|
||||
|
||||
SequelizeSlugify.slugifyModel(Event, { source: ['title'] })
|
||||
|
||||
Event.prototype.toAPNote = function (username, locale, to = []) {
|
||||
const tags = this.tags && this.tags.map(t => t.tag.replace(/[ #]/g, '_'))
|
||||
const plainDescription = htmlToText.fromString(this.description && this.description.replace('\n', '').slice(0, 1000))
|
||||
|
||||
Reference in New Issue
Block a user