diff --git a/api/collections/articles.yml b/api/collections/articles.yml
index a6de6f7..ac4205f 100644
--- a/api/collections/articles.yml
+++ b/api/collections/articles.yml
@@ -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
diff --git a/api/collections/content.yml b/api/collections/content.yml
index 57c79e6..8282c3d 100644
--- a/api/collections/content.yml
+++ b/api/collections/content.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: "
{{ article.content.title }}
{{ article.general.locale }}
" }
- name: tags
type: string[]
meta:
diff --git a/api/collections/fields/article/_article.yml b/api/collections/fields/article/_article.yml
index a8f90fd..49cbed8 100644
--- a/api/collections/fields/article/_article.yml
+++ b/api/collections/fields/article/_article.yml
@@ -5,7 +5,7 @@ meta:
label:
de: Einstellungen zum Artikel
en: Article Setings
- activeTab: 0
+ activeTab: 1
subFields:
- name: general
type: object
diff --git a/api/hooks/articles/post_create.js b/api/hooks/articles/post_create.js
new file mode 100644
index 0000000..22bb847
--- /dev/null
+++ b/api/hooks/articles/post_create.js
@@ -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
+})()
diff --git a/api/hooks/articles/put_update.js b/api/hooks/articles/put_update.js
new file mode 100644
index 0000000..22bb847
--- /dev/null
+++ b/api/hooks/articles/put_update.js
@@ -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
+})()
diff --git a/api/hooks/lib/helper.js b/api/hooks/lib/helper.js
new file mode 100644
index 0000000..67dcc0e
--- /dev/null
+++ b/api/hooks/lib/helper.js
@@ -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,
+}
diff --git a/src/components/routes/Content.svelte b/src/components/routes/Content.svelte
index 1ff3f82..3405df2 100644
--- a/src/components/routes/Content.svelte
+++ b/src/components/routes/Content.svelte
@@ -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) => {