From cb5fd239535e6a2371bd4cf229e39be26f31367e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20Demirel?= Date: Sun, 29 Mar 2026 19:53:57 +0300 Subject: [PATCH 1/3] feat: next-prev article buttons implemented --- scripts/update-data.mjs | 2 +- src/components/ArticleNav.astro | 92 +++++++++++++++++++ src/content.config.ts | 1 + .../articles/tr/linear-model-nedir.mdx | 1 + .../articles/tr/linear-regression-nedir.mdx | 1 + .../articles/tr/supervised-learning-nedir.mdx | 1 + src/data/tr/articles.json | 9 +- src/pages/articles/[slug].astro | 3 + src/pages/en/articles/[slug].astro | 3 + 9 files changed, 109 insertions(+), 4 deletions(-) create mode 100644 src/components/ArticleNav.astro diff --git a/scripts/update-data.mjs b/scripts/update-data.mjs index e6d4f83..3d1b354 100755 --- a/scripts/update-data.mjs +++ b/scripts/update-data.mjs @@ -89,7 +89,7 @@ const writeJSON = async (file, data) => await fs.writeFile(file, JSON.stringify( } } - articles.push({ title, slug, category: data.category?.trim() ?? '' }) + articles.push({ title, slug, category: data.category?.trim() ?? '', order: data.order ?? 0 }) } const filteredTags = tags.filter((t) => (t.articleCount ?? 0) > 0) diff --git a/src/components/ArticleNav.astro b/src/components/ArticleNav.astro new file mode 100644 index 0000000..0a96ee7 --- /dev/null +++ b/src/components/ArticleNav.astro @@ -0,0 +1,92 @@ +--- +import { getCollection } from 'astro:content' + +interface Props { + slug: string + category: string + lang: string +} + +const { slug, category, lang } = Astro.props + +const allArticles = await getCollection('articles') + +const categoryArticles = allArticles + .filter((a) => a.data.lang === lang && a.data.category === category && a.data.status === 'Published') + .map((a) => ({ slug: a.data.slug, title: a.data.title, order: a.data.order ?? 0 })) + .sort((a, b) => { + if (a.order === 0 && b.order === 0) return 0 + if (a.order === 0) return 1 + if (b.order === 0) return -1 + if (a.order === b.order) return Math.random() - 0.5 + return a.order - b.order + }) + +const currentIndex = categoryArticles.findIndex((a) => a.slug === slug) + +const prevArticle = currentIndex > 0 ? categoryArticles[currentIndex - 1] : null +const nextArticle = currentIndex < categoryArticles.length - 1 ? categoryArticles[currentIndex + 1] : null + +const langPrefix = lang === 'en' ? '/en' : '' +const isOnlyPrev = prevArticle && !nextArticle +const isOnlyNext = nextArticle && !prevArticle +--- + +{ + (prevArticle || nextArticle) && ( + + ) +} diff --git a/src/content.config.ts b/src/content.config.ts index 3db7d5b..70f6fd0 100644 --- a/src/content.config.ts +++ b/src/content.config.ts @@ -26,6 +26,7 @@ const articles = defineCollection({ author: z.string(), date: z.union([z.string(), z.date()]), views: z.number().default(0), + order: z.number().default(0), status: z.enum(['Published', 'Draft']).default('Published'), }), }) diff --git a/src/content/articles/tr/linear-model-nedir.mdx b/src/content/articles/tr/linear-model-nedir.mdx index 9b61ef1..107b473 100644 --- a/src/content/articles/tr/linear-model-nedir.mdx +++ b/src/content/articles/tr/linear-model-nedir.mdx @@ -8,6 +8,7 @@ tags: ['linear-regression', 'supervised-learning', 'teori'] author: '@omerfdmrl' date: '2026-03-29' views: 0 +order: 3 status: 'Published' --- diff --git a/src/content/articles/tr/linear-regression-nedir.mdx b/src/content/articles/tr/linear-regression-nedir.mdx index df24d76..13271c7 100644 --- a/src/content/articles/tr/linear-regression-nedir.mdx +++ b/src/content/articles/tr/linear-regression-nedir.mdx @@ -8,6 +8,7 @@ tags: ['linear-regression', 'supervised-learning', 'teori'] author: '@omerfdmrl' date: '2026-03-22' views: 0 +order: 2 status: 'Published' --- diff --git a/src/content/articles/tr/supervised-learning-nedir.mdx b/src/content/articles/tr/supervised-learning-nedir.mdx index 2615faf..e487437 100644 --- a/src/content/articles/tr/supervised-learning-nedir.mdx +++ b/src/content/articles/tr/supervised-learning-nedir.mdx @@ -8,6 +8,7 @@ tags: ['supervised-learning', 'teori'] author: '@omerfdmrl' date: '2026-03-21' views: 0 +order: 1 status: 'Published' --- diff --git a/src/data/tr/articles.json b/src/data/tr/articles.json index 0badc07..e8a46e8 100644 --- a/src/data/tr/articles.json +++ b/src/data/tr/articles.json @@ -2,16 +2,19 @@ { "title": "Linear Model Nedir?", "slug": "linear-model-nedir", - "category": "machine-learning" + "category": "machine-learning", + "order": 1 }, { "title": "Linear Regression Nedir?", "slug": "linear-regression-nedir", - "category": "machine-learning" + "category": "machine-learning", + "order": 2 }, { "title": "Supervised Learning Nedir?", "slug": "supervised-learning-nedir", - "category": "machine-learning" + "category": "machine-learning", + "order": 3 } ] diff --git a/src/pages/articles/[slug].astro b/src/pages/articles/[slug].astro index b9d7dc1..f861c38 100644 --- a/src/pages/articles/[slug].astro +++ b/src/pages/articles/[slug].astro @@ -4,6 +4,7 @@ import ShareButtons from '../../components/ShareButtons.astro' import GitHubUserCard from '../../components/GitHubUserCard.astro' import ReadingProgress from '../../components/ReadingProgress.astro' import TableOfContents from '../../components/TableOfContents.astro' +import ArticleNav from '../../components/ArticleNav.astro' import { getCollection, render } from 'astro:content' import { SITE } from '../../config.mjs' import { getLangFromUrl, t } from '../../i18n/index.ts' @@ -153,6 +154,8 @@ const onThisPageLabel = t(labels, 'article.onThisPage') + + diff --git a/src/pages/en/articles/[slug].astro b/src/pages/en/articles/[slug].astro index 856c651..fe18fa9 100644 --- a/src/pages/en/articles/[slug].astro +++ b/src/pages/en/articles/[slug].astro @@ -4,6 +4,7 @@ import ShareButtons from '../../../components/ShareButtons.astro' import GitHubUserCard from '../../../components/GitHubUserCard.astro' import ReadingProgress from '../../../components/ReadingProgress.astro' import TableOfContents from '../../../components/TableOfContents.astro' +import ArticleNav from '../../../components/ArticleNav.astro' import { getCollection, render } from 'astro:content' import { SITE } from '../../../config.mjs' import { t } from '../../../i18n/index.ts' @@ -152,6 +153,8 @@ const onThisPageLabel = t(labels, 'article.onThisPage') + + From 881fc9cc09591ace9816ed358c835be57c22bd58 Mon Sep 17 00:00:00 2001 From: omerfdmrl <62325045+omerfdmrl@users.noreply.github.com> Date: Sun, 29 Mar 2026 16:54:51 +0000 Subject: [PATCH 2/3] chore: auto-generate data and og images --- src/data/tr/articles.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/data/tr/articles.json b/src/data/tr/articles.json index e8a46e8..1eedeca 100644 --- a/src/data/tr/articles.json +++ b/src/data/tr/articles.json @@ -3,7 +3,7 @@ "title": "Linear Model Nedir?", "slug": "linear-model-nedir", "category": "machine-learning", - "order": 1 + "order": 3 }, { "title": "Linear Regression Nedir?", @@ -15,6 +15,6 @@ "title": "Supervised Learning Nedir?", "slug": "supervised-learning-nedir", "category": "machine-learning", - "order": 3 + "order": 1 } ] From f2f0efb830142da0afea7c56604a8bfb70f9bf1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20Demirel?= Date: Sun, 29 Mar 2026 19:59:54 +0300 Subject: [PATCH 3/3] refactor: multilanguage added to article navigation --- src/components/ArticleNav.astro | 8 +++++--- src/data/en/labels.json | 4 +++- src/data/tr/labels.json | 4 +++- src/pages/articles/[slug].astro | 7 ++++++- src/pages/en/articles/[slug].astro | 2 +- 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/components/ArticleNav.astro b/src/components/ArticleNav.astro index 0a96ee7..63e89d9 100644 --- a/src/components/ArticleNav.astro +++ b/src/components/ArticleNav.astro @@ -1,13 +1,15 @@ --- import { getCollection } from 'astro:content' +import { t } from '../i18n/index.ts' interface Props { slug: string category: string lang: string + labels?: Record } -const { slug, category, lang } = Astro.props +const { slug, category, lang, labels = {} } = Astro.props const allArticles = await getCollection('articles') @@ -57,7 +59,7 @@ const isOnlyNext = nextArticle && !prevArticle
- Previous + {t(labels, 'article.previous')} {prevArticle.title}
@@ -68,7 +70,7 @@ const isOnlyNext = nextArticle && !prevArticle href={`${langPrefix}/articles/${nextArticle.slug}`} >
- Next + {t(labels, 'article.next')} {nextArticle.title}
- + diff --git a/src/pages/en/articles/[slug].astro b/src/pages/en/articles/[slug].astro index fe18fa9..565fdee 100644 --- a/src/pages/en/articles/[slug].astro +++ b/src/pages/en/articles/[slug].astro @@ -153,7 +153,7 @@ const onThisPageLabel = t(labels, 'article.onThisPage') - +