feat: feed feature, typescript, remove google, fix errs & warns
publish / Build-and-publish (push) Successful in 13m32s

This commit is contained in:
Unknown
2026-07-17 22:22:29 +01:00
parent 2c42ecae5f
commit 8a10d127c1
55 changed files with 1887 additions and 587 deletions
+172 -1
View File
@@ -6,6 +6,10 @@ const recentPosts = []
const archives = {}
const tagsFrequent = []
const feedRecentPosts = []
const feedArchives = {}
const feedTagsFrequent = []
exports.createPages = async ({ graphql, actions, reporter }) => {
const { createPage } = actions
@@ -14,6 +18,10 @@ exports.createPages = async ({ graphql, actions, reporter }) => {
const blogListTemplate = path.resolve(`./src/templates/blog-list.tsx`)
const blogSearchTemplate = path.resolve(`./src/templates/blog-search.tsx`)
// Define a template for feed post
const feedPostTemplate = path.resolve(`./src/templates/feed-post.tsx`)
const feedListTemplate = path.resolve(`./src/templates/feed-list.tsx`)
// Get all markdown blog posts sorted by date
const result = await graphql(
`
@@ -34,7 +42,10 @@ exports.createPages = async ({ graphql, actions, reporter }) => {
}
}
}
tagsGroup: allMarkdownRemark(limit: 1000) {
tagsGroup: allMarkdownRemark(
limit: 1000
filter: { fileAbsolutePath: { regex: "/content/blog/" } }
) {
group(field: { frontmatter: { tags: SELECT } }) {
name: fieldValue
totalCount
@@ -176,6 +187,166 @@ exports.createPages = async ({ graphql, actions, reporter }) => {
tags: tagsFrequent
}
})
// ---------------------------------------------------------------------
// Feed section (announcements / social updates) - mirrors the blog logic
// above but is scoped to /content/feed/ and lives under the /feed/ path
// ---------------------------------------------------------------------
const feedResult = await graphql(
`
{
allMarkdownRemark(
sort: { frontmatter: { date: DESC } }
limit: 1000
filter: { fileAbsolutePath: { regex: "/content/feed/" } }
) {
nodes {
id
fields {
slug
}
frontmatter {
title
date(formatString: "YYYY")
}
}
}
tagsGroup: allMarkdownRemark(
limit: 1000
filter: { fileAbsolutePath: { regex: "/content/feed/" } }
) {
group(field: { frontmatter: { tags: SELECT } }) {
name: fieldValue
totalCount
}
}
}
`
)
if (feedResult.errors) {
reporter.panicOnBuild(
`There was an error loading your feed posts`,
feedResult.errors
)
return
}
const feedPosts = feedResult.data.allMarkdownRemark.nodes
feedRecentPosts.push(
...feedPosts.slice(0, 10).map((p) => ({
slug: p.fields.slug,
title: p.frontmatter.title
}))
)
const feedTags = feedResult.data.tagsGroup.group
feedTagsFrequent.push(
...feedTags.sort((a, b) => b.totalCount - a.totalCount).slice(0, 10)
)
feedPosts.forEach((d) => {
if (feedArchives[d.frontmatter.date] == null)
feedArchives[d.frontmatter.date] = 0
feedArchives[d.frontmatter.date]++
})
// Create individual feed post pages
if (feedPosts.length > 0) {
feedPosts.forEach((post, index) => {
const previousPostId = index === 0 ? null : feedPosts[index - 1].id
const nextPostId =
index === feedPosts.length - 1 ? null : feedPosts[index + 1].id
createPage({
path: post.fields.slug,
component: feedPostTemplate,
context: {
id: post.id,
archives: feedArchives,
recentPosts: feedRecentPosts,
tags: feedTagsFrequent,
previousPostId,
nextPostId
}
})
})
}
// Create feed-list pages
const feedNumPages = Math.ceil(feedPosts.length / postsPerPage)
Array.from({ length: feedNumPages }).forEach((_, i) => {
createPage({
path: i === 0 ? `/feed` : `/feed/page/${i + 1}`,
component: feedListTemplate,
context: {
page: 'index',
archives: feedArchives,
recentPosts: feedRecentPosts,
tags: feedTagsFrequent,
filter: { fileAbsolutePath: { regex: '/content/feed/' } },
limit: postsPerPage,
skip: i * postsPerPage,
numPages: feedNumPages,
currentPage: i + 1
}
})
})
for (year in feedArchives) {
const count = feedArchives[year]
const numPagesOfYear = Math.ceil(count / postsPerPage)
Array.from({ length: numPagesOfYear }).forEach((_, i) => {
createPage({
path:
i === 0 ? `/feed/${year}/` : `/feed/${year}/page/${i + 1}`,
component: feedListTemplate,
context: {
page: 'year',
archives: feedArchives,
recentPosts: feedRecentPosts,
tags: feedTagsFrequent,
filter: {
frontmatter: { date: { gte: year, lt: year + 1 } },
fileAbsolutePath: { regex: '/content/feed/' }
},
limit: postsPerPage,
skip: i * postsPerPage,
numPages: numPagesOfYear,
currentPage: i + 1,
year: year
}
})
})
}
feedTags.forEach((tag) => {
const count = tag.totalCount
const numPagesOfTag = Math.ceil(count / postsPerPage)
Array.from({ length: numPagesOfTag }).forEach((__, i) => {
const tagPath = `/feed/category/${_.kebabCase(tag.name)}/`
createPage({
path: i === 0 ? tagPath : `${tagPath}page/${i + 1}`,
component: feedListTemplate,
context: {
page: 'category',
archives: feedArchives,
recentPosts: feedRecentPosts,
tags: feedTagsFrequent,
filter: {
frontmatter: { tags: { in: [tag.name] } },
fileAbsolutePath: { regex: '/content/feed/' }
},
limit: postsPerPage,
skip: i * postsPerPage,
numPages: numPagesOfTag,
currentPage: i + 1,
tag: tag.name
}
})
})
})
}
exports.onCreatePage = ({ page, actions }) => {