mirror of
https://github.com/privacy-scaling-explorations/pse.dev.git
synced 2026-04-23 03:01:03 -04:00
- [x] Add blog post feed to project pages #368 - [x] update readme - [x] fix blog tags
This commit is contained in:
committed by
Meyanis95
parent
313480620f
commit
741c823bcd
17
lib/blog.ts
17
lib/blog.ts
@@ -16,13 +16,18 @@ export interface Article {
|
||||
hash?: string
|
||||
canonical?: string
|
||||
tags?: string[]
|
||||
projects?: string[]
|
||||
}
|
||||
|
||||
const articlesDirectory = path.join(process.cwd(), "articles")
|
||||
|
||||
// Get all articles from /articles
|
||||
export function getArticles(options?: { limit?: number; tag?: string }) {
|
||||
const { limit = 1000, tag } = options ?? {}
|
||||
export function getArticles(options?: {
|
||||
limit?: number
|
||||
tag?: string
|
||||
project?: string
|
||||
}) {
|
||||
const { limit = 1000, tag, project } = options ?? {}
|
||||
// Get file names under /articles
|
||||
const fileNames = fs.readdirSync(articlesDirectory)
|
||||
const allArticlesData = fileNames.map((fileName: string) => {
|
||||
@@ -91,6 +96,14 @@ export function getArticles(options?: { limit?: number; tag?: string }) {
|
||||
)
|
||||
}
|
||||
|
||||
// Filter by project if provided
|
||||
if (project) {
|
||||
filteredArticles = filteredArticles.filter(
|
||||
(article) =>
|
||||
Array.isArray(article.projects) && article.projects.includes(project)
|
||||
)
|
||||
}
|
||||
|
||||
// Sort posts by date
|
||||
return filteredArticles
|
||||
.sort((a, b) => {
|
||||
|
||||
Reference in New Issue
Block a user