forked from cms/tibi-svelte-starter
Möglichkeit, in die Artikel-Details zu springen implementiert, ohne einen extra URL Pfad zu benötigen.
This commit is contained in:
parent
65e8b7ffc8
commit
652f15830d
@ -114,10 +114,6 @@ permissions:
|
|||||||
# update:
|
# update:
|
||||||
# type: javascript
|
# type: javascript
|
||||||
# file: hooks/article/put_return.js
|
# file: hooks/article/put_return.js
|
||||||
# delete:
|
|
||||||
# return:
|
|
||||||
# type: javascript
|
|
||||||
# file: hooks/article/delete_return.js
|
|
||||||
|
|
||||||
fields:
|
fields:
|
||||||
- !include fields/_article.yml
|
- !include fields/article/_article.yml
|
||||||
|
@ -24,7 +24,7 @@ subFields:
|
|||||||
helperText:
|
helperText:
|
||||||
de: "Der Artikel wird auf der Seite angezeigt."
|
de: "Der Artikel wird auf der Seite angezeigt."
|
||||||
en: "This article is displayed on the page."
|
en: "This article is displayed on the page."
|
||||||
- !include _locale.yml
|
- !include ../_locale.yml
|
||||||
- name: tags
|
- name: tags
|
||||||
type: string[]
|
type: string[]
|
||||||
meta:
|
meta:
|
@ -1,17 +1,19 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { _ } from "svelte-i18n"
|
import { _ } from "svelte-i18n"
|
||||||
import { getContent } from "../../api"
|
import { getContent, getArticles } from "../../api"
|
||||||
import { generalInfo, currentLang, location } from "../../store"
|
import { generalInfo, currentLang, location } from "../../store"
|
||||||
import { navigate } from "svelte-routing"
|
import { navigate } from "svelte-routing"
|
||||||
|
|
||||||
import Image from "../widgets/Image.svelte"
|
import Image from "../widgets/Image.svelte"
|
||||||
import ArticlesList from "../widgets/ArticlesList.svelte"
|
import ArticlesList from "../widgets/ArticlesList.svelte"
|
||||||
// import Article from "../widgets/Article.svelte"
|
import Article from "../widgets/Article.svelte"
|
||||||
|
|
||||||
export let path: string
|
export let path: string
|
||||||
|
let oldPath: string = null
|
||||||
|
|
||||||
let loading = true
|
let loading = true
|
||||||
let content: Content
|
let content: Content
|
||||||
|
let article: TibiArticle
|
||||||
let connectedContentNotFound: boolean = false
|
let connectedContentNotFound: boolean = false
|
||||||
$: currentDomain = window.location.protocol + "//" + window.location.host
|
$: currentDomain = window.location.protocol + "//" + window.location.host
|
||||||
|
|
||||||
@ -40,6 +42,7 @@
|
|||||||
let apiParams: APIParams = {
|
let apiParams: APIParams = {
|
||||||
filter,
|
filter,
|
||||||
}
|
}
|
||||||
|
|
||||||
loading = true
|
loading = true
|
||||||
getContent(apiParams)
|
getContent(apiParams)
|
||||||
.then((c) => {
|
.then((c) => {
|
||||||
@ -60,6 +63,8 @@
|
|||||||
content = null
|
content = null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
oldPath = path
|
||||||
|
|
||||||
// Redirect to HOME if no content has been found. So the page 404 content will never shown.
|
// Redirect to HOME if no content has been found. So the page 404 content will never shown.
|
||||||
if (!content) {
|
if (!content) {
|
||||||
navigate("/")
|
navigate("/")
|
||||||
@ -70,13 +75,59 @@
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const loadArticle = (type?: string) => {
|
||||||
|
let pathParts = path.split("/")
|
||||||
|
let slug = pathParts[pathParts.length - 1]
|
||||||
|
|
||||||
|
// Set default API call filter
|
||||||
|
let filter = {
|
||||||
|
"article.general.locale": $currentLang,
|
||||||
|
"article.content.slug": slug,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Changed filter to find simmilar content for changed language
|
||||||
|
if (type === "changedLanguage") {
|
||||||
|
// filter = {
|
||||||
|
// tags: { $in: content?.tags },
|
||||||
|
// locale: $currentLang,
|
||||||
|
// }
|
||||||
|
// delete filter["article.general.locale"]
|
||||||
|
// delete filter["article.content.slug"]
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get content by API call
|
||||||
|
let apiParams: APIParams = {
|
||||||
|
filter,
|
||||||
|
}
|
||||||
|
loading = true
|
||||||
|
getArticles("articles", apiParams)
|
||||||
|
.then((respoonse) => {
|
||||||
|
article = respoonse[0]
|
||||||
|
oldPath = path
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
loading = false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
currentLang.subscribe(() => {
|
currentLang.subscribe(() => {
|
||||||
if (content) {
|
if (content) {
|
||||||
loadContent("changedLanguage")
|
loadContent("changedLanguage")
|
||||||
|
} else if (article) {
|
||||||
|
loadArticle("changedLanguage")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
$: if (path) loadContent()
|
$: if (path) {
|
||||||
|
content = null
|
||||||
|
article = null
|
||||||
|
|
||||||
|
if (window.location.pathname.endsWith("/")) {
|
||||||
|
loadContent()
|
||||||
|
} else {
|
||||||
|
loadArticle()
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:head>
|
<svelte:head>
|
||||||
@ -114,12 +165,9 @@
|
|||||||
|
|
||||||
{#if loading}
|
{#if loading}
|
||||||
<!-- Loader -->
|
<!-- Loader -->
|
||||||
|
{:else if article}
|
||||||
|
<Article entry="{article}" showDetails />
|
||||||
{:else if content}
|
{:else if content}
|
||||||
<!--
|
|
||||||
{#each content.blocks || [] as b}
|
|
||||||
{JSON.stringify(b)}
|
|
||||||
{/each}
|
|
||||||
-->
|
|
||||||
<ArticlesList path="{path}" tags="{content?.tags}" />
|
<ArticlesList path="{path}" tags="{content?.tags}" />
|
||||||
{:else}
|
{:else}
|
||||||
<div class="page-404">
|
<div class="page-404">
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { fade } from "svelte/transition"
|
|
||||||
import { _ } from "svelte-i18n"
|
import { _ } from "svelte-i18n"
|
||||||
// import { navigate } from "svelte-routing"
|
import { navigate, link } from "svelte-routing"
|
||||||
|
|
||||||
import TibiArticleMediaFile from "./TibiArticleMediaFile.svelte"
|
import TibiArticleMediaFile from "./TibiArticleMediaFile.svelte"
|
||||||
|
|
||||||
@ -9,6 +8,7 @@
|
|||||||
export let cssClass: string = ""
|
export let cssClass: string = ""
|
||||||
export let showDetails: boolean = false
|
export let showDetails: boolean = false
|
||||||
|
|
||||||
|
let path = window.location.pathname
|
||||||
let article = null
|
let article = null
|
||||||
if (entry) {
|
if (entry) {
|
||||||
article = entry.article
|
article = entry.article
|
||||||
@ -201,6 +201,21 @@
|
|||||||
|
|
||||||
{#if article?.content?.types?.details && showDetails}
|
{#if article?.content?.types?.details && showDetails}
|
||||||
<div class="article-details">{@html article?.content?.types?.details}</div>
|
<div class="article-details">{@html article?.content?.types?.details}</div>
|
||||||
|
{:else if article?.content?.types?.details}
|
||||||
|
<a
|
||||||
|
use:link
|
||||||
|
href="{`${path}${encodeURIComponent(
|
||||||
|
article?.content?.slug
|
||||||
|
? article?.content?.slug
|
||||||
|
.toLowerCase()
|
||||||
|
.replace(/[^a-zA-Z0-9]/g, '-')
|
||||||
|
.replaceAll('---', '--')
|
||||||
|
: entry.id
|
||||||
|
)}`}"
|
||||||
|
class="article-link"
|
||||||
|
>
|
||||||
|
{@html article?.link?.text ? article?.link?.text : $_("details")}
|
||||||
|
</a>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -40,7 +40,7 @@
|
|||||||
{item.settings.title}
|
{item.settings.title}
|
||||||
</a>
|
</a>
|
||||||
{:else}
|
{:else}
|
||||||
<a href="{item.settings.page}" class:active="{'/' + item.settings.page === $location.path}">
|
<a href="{item.settings.page + '/'}" class:active="{'/' + item.settings.page === $location.path}">
|
||||||
{item.settings.title}
|
{item.settings.title}
|
||||||
</a>
|
</a>
|
||||||
{/if}
|
{/if}
|
||||||
@ -70,7 +70,7 @@
|
|||||||
{:else}
|
{:else}
|
||||||
<div class="nav-item">
|
<div class="nav-item">
|
||||||
<a
|
<a
|
||||||
href="{item.settings.page}"
|
href="{item.settings.page + '/'}"
|
||||||
on:click="{() => (showMobileNav = false)}"
|
on:click="{() => (showMobileNav = false)}"
|
||||||
class:active="{'/' + item.settings.page === $location.path}"
|
class:active="{'/' + item.settings.page === $location.path}"
|
||||||
>
|
>
|
||||||
|
@ -22,6 +22,7 @@ article,
|
|||||||
}
|
}
|
||||||
|
|
||||||
.article-link {
|
.article-link {
|
||||||
|
cursor: pointer;
|
||||||
text-decoration: underline;
|
text-decoration: underline;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user