diff --git a/src/lib/components/SEO/IndexSEO.svelte b/src/lib/components/SEO/IndexSEO.svelte index fe7e2c4..1bd2eb4 100644 --- a/src/lib/components/SEO/IndexSEO.svelte +++ b/src/lib/components/SEO/IndexSEO.svelte @@ -16,7 +16,7 @@ "url": "https://blog.nanao.moe/", "image": { "@type": "ImageObject", - "url": "https://blog.nanao.moe/images/default-header.jpg" + "url": "https://blog.nanao.moe/images/default-feature.jpg" }, "mainEntityOfPage": { "@type": "WebPage", @@ -34,13 +34,13 @@ - + - + {@html schemaOrg} diff --git a/src/lib/content/contentApi.ts b/src/lib/content/contentApi.ts index 3b96198..342be2d 100644 --- a/src/lib/content/contentApi.ts +++ b/src/lib/content/contentApi.ts @@ -16,6 +16,28 @@ export const browsePost = async (page = 1) => { return posts } +export const browseNextPost = async (id: string) => { + const posts = await api.posts.browse({ limit: 1, filter: [`id:>${id}`], order: 'id ASC' }); + + if (posts.length > 0) { + return posts[0]; + } + return null; +} +export const browsePrevPost = async (id: string) => { + const posts = await api.posts.browse({ limit: 1, filter: [`id:<${id}`], order: 'id DESC' }); + + if (posts.length > 0) { + return posts[0]; + } + return null; +} +export const browseRelatedPost = async (tag: string | undefined, id: string) => { + const tagCondition = tag ? [`tag:${tag}`] : [] + const posts = await api.posts.browse({ limit: 3, filter: [...tagCondition, ...[`id:-${id}`]], order: 'published_at DESC', include: ['tags', 'authors'] }); + + return posts; +} export const browseAllPost = async (page = 1) => { const posts = await api.posts.browse({ limit: 'all' }); @@ -34,7 +56,7 @@ export const browsePostWithAuthor = async (slug: string, page = 1) => { export const readPost = async (slug: string) => { try { const post = await api.posts.read({ slug }, { include: ['tags', 'authors'] }); - + return post; } catch (e) { return null; @@ -44,7 +66,7 @@ export const readPost = async (slug: string) => { export const readTag = async (slug: string) => { try { const tag = await api.tags.read({ slug }); - + return tag; } catch (e) { return null; diff --git a/src/routes/[tag]/[slug].svelte b/src/routes/[tag]/[slug].svelte index 6272391..f5bf352 100644 --- a/src/routes/[tag]/[slug].svelte +++ b/src/routes/[tag]/[slug].svelte @@ -1,18 +1,24 @@ @@ -29,15 +35,26 @@ import PostRelated from '@damillora/plachta/components/Post/PostRelated.svelte'; import PostCard from '@damillora/plachta/components/PostCard/PostCard.svelte'; import type { Load } from '@sveltejs/kit'; - import { readPost } from '$lib/content/contentApi'; + import { + browseNextPost, + browsePrevPost, + browseRelatedPost, + readPost + } from '$lib/content/contentApi'; import { browser } from '$app/env'; import PostSeo from '$lib/components/SEO/PostSEO.svelte'; + import { onMount } from 'svelte'; export let post: any; + export let prevPost: any; + export let nextPost: any; + export let relatedPost: any[]; - if (browser) { - fitvids(); - } + onMount(() => { + if (browser) { + fitvids(); + } + }); @@ -60,78 +77,21 @@ {@html post.html} - + - - - - + + {#each relatedPost as post} + + {/each} diff --git a/src/routes/__layout.svelte b/src/routes/__layout.svelte index a48c27f..bbe57e8 100644 --- a/src/routes/__layout.svelte +++ b/src/routes/__layout.svelte @@ -44,7 +44,7 @@ Damillora's Virtual Memoir - +