forked from cms/tibi-svelte-starter
Update SLUG field in server side post_create and put_update hooks.
This commit is contained in:
parent
49896d6978
commit
dbbd7c63ed
@ -107,15 +107,15 @@ permissions:
|
||||
put: false
|
||||
delete: false
|
||||
|
||||
# hooks:
|
||||
# post:
|
||||
# create:
|
||||
# type: javascript
|
||||
# file: hooks/article/post_create.js
|
||||
# put:
|
||||
# update:
|
||||
# type: javascript
|
||||
# file: hooks/article/put_return.js
|
||||
hooks:
|
||||
post:
|
||||
create:
|
||||
type: javascript
|
||||
file: hooks/articles/post_create.js
|
||||
put:
|
||||
update:
|
||||
type: javascript
|
||||
file: hooks/articles/put_update.js
|
||||
|
||||
fields:
|
||||
- !include fields/article/_article.yml
|
||||
|
@ -176,9 +176,9 @@ fields:
|
||||
choices:
|
||||
endpoint: "articles"
|
||||
params:
|
||||
sort: "article.publish_date.from"
|
||||
sort: "article.general.publish_date.from"
|
||||
filter: { "article.assignments.pages": { source: "path" } }
|
||||
template: { twig: "{{ article.content.title }}" }
|
||||
template: { twig: "<div>{{ article.content.title }}</div><div>{{ article.general.locale }}</div>" }
|
||||
- name: tags
|
||||
type: string[]
|
||||
meta:
|
||||
|
@ -5,7 +5,7 @@ meta:
|
||||
label:
|
||||
de: Einstellungen zum Artikel
|
||||
en: Article Setings
|
||||
activeTab: 0
|
||||
activeTab: 1
|
||||
subFields:
|
||||
- name: general
|
||||
type: object
|
||||
|
11
api/hooks/articles/post_create.js
Normal file
11
api/hooks/articles/post_create.js
Normal file
@ -0,0 +1,11 @@
|
||||
// @ts-check
|
||||
const { generateArticleSlugUrlString: generateSlugUrlStringByArticle } = require("../lib/helper")
|
||||
|
||||
;(function () {
|
||||
/** @type {import("tibi-types").HookResponse} */
|
||||
let hookResponse
|
||||
|
||||
context.data.article.content.slug = generateSlugUrlStringByArticle(context.data.article)
|
||||
|
||||
return hookResponse
|
||||
})()
|
11
api/hooks/articles/put_update.js
Normal file
11
api/hooks/articles/put_update.js
Normal file
@ -0,0 +1,11 @@
|
||||
// @ts-check
|
||||
const { generateArticleSlugUrlString: generateSlugUrlStringByArticle } = require("../lib/helper")
|
||||
|
||||
;(function () {
|
||||
/** @type {import("tibi-types").HookResponse} */
|
||||
let hookResponse
|
||||
|
||||
context.data.article.content.slug = generateSlugUrlStringByArticle(context.data.article)
|
||||
|
||||
return hookResponse
|
||||
})()
|
17
api/hooks/lib/helper.js
Normal file
17
api/hooks/lib/helper.js
Normal file
@ -0,0 +1,17 @@
|
||||
const generateArticleSlugUrlString = (article) => {
|
||||
let slug = article.content.slug
|
||||
let title = article.content.title
|
||||
|
||||
if (!slug || slug === "") {
|
||||
slug = title
|
||||
.replace(/[^a-zA-Z0-9 ]/g, "")
|
||||
.replace(/\s/g, "-")
|
||||
.toLowerCase()
|
||||
}
|
||||
|
||||
return slug
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
generateArticleSlugUrlString,
|
||||
}
|
@ -72,12 +72,13 @@
|
||||
|
||||
const loadArticle = (type?: string) => {
|
||||
let pathParts = path.split("/")
|
||||
let slug = pathParts[pathParts.length - 1]
|
||||
let slugOrId = pathParts[pathParts.length - 1].toString()
|
||||
|
||||
// Set default API call filter
|
||||
|
||||
let filter = {
|
||||
"article.general.locale": $currentLang,
|
||||
"article.content.slug": slug,
|
||||
"article.content.slug": slugOrId,
|
||||
}
|
||||
|
||||
// Changed filter to find simmilar content for changed language
|
||||
@ -94,6 +95,7 @@
|
||||
let apiParams: APIParams = {
|
||||
filter,
|
||||
}
|
||||
|
||||
loading = true
|
||||
getArticles("articles", apiParams)
|
||||
.then((respoonse) => {
|
||||
|
Loading…
Reference in New Issue
Block a user