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
|
put: false
|
||||||
delete: false
|
delete: false
|
||||||
|
|
||||||
# hooks:
|
hooks:
|
||||||
# post:
|
post:
|
||||||
# create:
|
create:
|
||||||
# type: javascript
|
type: javascript
|
||||||
# file: hooks/article/post_create.js
|
file: hooks/articles/post_create.js
|
||||||
# put:
|
put:
|
||||||
# update:
|
update:
|
||||||
# type: javascript
|
type: javascript
|
||||||
# file: hooks/article/put_return.js
|
file: hooks/articles/put_update.js
|
||||||
|
|
||||||
fields:
|
fields:
|
||||||
- !include fields/article/_article.yml
|
- !include fields/article/_article.yml
|
||||||
|
@ -176,9 +176,9 @@ fields:
|
|||||||
choices:
|
choices:
|
||||||
endpoint: "articles"
|
endpoint: "articles"
|
||||||
params:
|
params:
|
||||||
sort: "article.publish_date.from"
|
sort: "article.general.publish_date.from"
|
||||||
filter: { "article.assignments.pages": { source: "path" } }
|
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
|
- name: tags
|
||||||
type: string[]
|
type: string[]
|
||||||
meta:
|
meta:
|
||||||
|
@ -5,7 +5,7 @@ meta:
|
|||||||
label:
|
label:
|
||||||
de: Einstellungen zum Artikel
|
de: Einstellungen zum Artikel
|
||||||
en: Article Setings
|
en: Article Setings
|
||||||
activeTab: 0
|
activeTab: 1
|
||||||
subFields:
|
subFields:
|
||||||
- name: general
|
- name: general
|
||||||
type: object
|
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) => {
|
const loadArticle = (type?: string) => {
|
||||||
let pathParts = path.split("/")
|
let pathParts = path.split("/")
|
||||||
let slug = pathParts[pathParts.length - 1]
|
let slugOrId = pathParts[pathParts.length - 1].toString()
|
||||||
|
|
||||||
// Set default API call filter
|
// Set default API call filter
|
||||||
|
|
||||||
let filter = {
|
let filter = {
|
||||||
"article.general.locale": $currentLang,
|
"article.general.locale": $currentLang,
|
||||||
"article.content.slug": slug,
|
"article.content.slug": slugOrId,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Changed filter to find simmilar content for changed language
|
// Changed filter to find simmilar content for changed language
|
||||||
@ -94,6 +95,7 @@
|
|||||||
let apiParams: APIParams = {
|
let apiParams: APIParams = {
|
||||||
filter,
|
filter,
|
||||||
}
|
}
|
||||||
|
|
||||||
loading = true
|
loading = true
|
||||||
getArticles("articles", apiParams)
|
getArticles("articles", apiParams)
|
||||||
.then((respoonse) => {
|
.then((respoonse) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user