Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
www
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PLN
www
Commits
ffcea4d1
Commit
ffcea4d1
authored
Apr 11, 2025
by
PLN (Algolia)
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: Filter, default poem fr
parent
a4365692
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
20 deletions
+35
-20
utils.js
next/lib/utils.js
+34
-19
poesie.js
next/pages/poesie.js
+1
-1
No files found.
next/lib/utils.js
View file @
ffcea4d1
...
@@ -5,19 +5,30 @@ import { remark } from 'remark';
...
@@ -5,19 +5,30 @@ import { remark } from 'remark';
import
remarkHtml
from
'remark-html'
;
import
remarkHtml
from
'remark-html'
;
function
getContentDirectory
(
name
)
{
function
getContentDirectory
(
name
)
{
return
path
.
join
(
process
.
cwd
(),
"content"
,
name
)
return
path
.
join
(
process
.
cwd
(),
"content"
,
name
);
}
// Helper function to check if a file is a markdown file
function
isMarkdownFile
(
fileName
)
{
return
fileName
.
endsWith
(
'.md'
)
&&
!
fileName
.
endsWith
(
'.mdx.md'
);
}
// Helper function to get ID from filename
function
getIdFromFileName
(
fileName
)
{
return
fileName
.
replace
(
/
\.
md$/
,
''
);
}
}
function
getAllContentData
(
name
,
sorted
=
false
)
{
function
getAllContentData
(
name
,
sorted
=
false
)
{
// Get file names under /content/{name}
// Get file names under /content/{name}
const
contentDirectory
=
getContentDirectory
(
name
);
const
contentDirectory
=
getContentDirectory
(
name
);
const
fileNames
=
fs
.
readdirSync
(
contentDirectory
);
const
fileNames
=
fs
.
readdirSync
(
contentDirectory
);
console
.
log
(
`getAllContentData: Found
${
fileNames
.
length
}
files in
${
name
}
`
);
const
allContentData
=
fileNames
const
allContentData
=
fileNames
.
filter
(
fileName
=>
fileName
.
endsWith
(
'.md'
))
// Keep only .md files
.
filter
(
isMarkdownFile
)
.
map
((
fileName
)
=>
{
.
map
((
fileName
)
=>
{
// Remove ".md" from file name to get id
const
id
=
getIdFromFileName
(
fileName
);
cons
t
id
=
fileName
.
replace
(
/
\.
md$/
,
""
);
cons
ole
.
log
(
`Processing
${
fileName
}
with id
${
id
}
`
);
// Read markdown file as string
// Read markdown file as string
const
fullPath
=
path
.
join
(
contentDirectory
,
fileName
);
const
fullPath
=
path
.
join
(
contentDirectory
,
fileName
);
...
@@ -46,22 +57,29 @@ function getAllContentData(name, sorted = false) {
...
@@ -46,22 +57,29 @@ function getAllContentData(name, sorted = false) {
function
getAllContentIds
(
name
)
{
function
getAllContentIds
(
name
)
{
const
fileNames
=
fs
.
readdirSync
(
getContentDirectory
(
name
));
const
fileNames
=
fs
.
readdirSync
(
getContentDirectory
(
name
));
console
.
log
(
`getAllContentIds:
${
fileNames
.
length
}
${
name
}
(s).
`
);
console
.
log
(
`getAllContentIds:
Found
${
fileNames
.
length
}
files in
${
name
}
`
);
return
fileNames
.
map
((
fileName
)
=>
{
return
fileNames
return
{
.
filter
(
isMarkdownFile
)
.
map
((
fileName
)
=>
({
params
:
{
params
:
{
id
:
fileName
.
replace
(
/
\.
md$/
,
""
),
id
:
getIdFromFileName
(
fileName
),
},
},
};
}));
});
}
}
async
function
getContentData
(
name
,
id
)
{
async
function
getContentData
(
name
,
id
)
{
const
fullPath
=
path
.
join
(
getContentDirectory
(
name
),
`
${
id
}
.md`
);
// Ensure we're looking for a .md file
console
.
log
(
"Got content fullPath:"
,
fullPath
);
const
fileName
=
`
${
id
}${
id
.
endsWith
(
'.md'
)
?
''
:
'.md'
}
`
;
const
fullPath
=
path
.
join
(
getContentDirectory
(
name
),
fileName
);
if
(
!
fs
.
existsSync
(
fullPath
))
{
console
.
error
(
`File not found:
${
fullPath
}
`
);
throw
new
Error
(
`No content found for
${
id
}
`
);
}
console
.
log
(
"Reading content from:"
,
fullPath
);
const
fileContents
=
fs
.
readFileSync
(
fullPath
,
"utf8"
);
const
fileContents
=
fs
.
readFileSync
(
fullPath
,
"utf8"
);
console
.
log
(
"Got contents:"
,
fileContents
);
// Use gray-matter to parse the post metadata section
// Use gray-matter to parse the post metadata section
const
matterResult
=
matter
(
fileContents
);
const
matterResult
=
matter
(
fileContents
);
...
@@ -71,20 +89,17 @@ async function getContentData(name, id) {
...
@@ -71,20 +89,17 @@ async function getContentData(name, id) {
.
use
(
remarkHtml
)
.
use
(
remarkHtml
)
.
process
(
matterResult
.
content
);
.
process
(
matterResult
.
content
);
const
contentHtml
=
processedContent
.
toString
();
const
contentHtml
=
processedContent
.
toString
();
console
.
log
(
matterResult
);
if
(
"description"
in
matterResult
.
data
)
{
if
(
"description"
in
matterResult
.
data
)
{
console
.
log
(
"Got desc!"
);
const
processedDescription
=
await
remark
()
const
processedDescription
=
await
remark
()
.
use
(
remarkHtml
)
.
use
(
remarkHtml
)
.
process
(
matterResult
.
data
.
description
);
.
process
(
matterResult
.
data
.
description
);
matterResult
.
data
.
description
=
processedContent
.
toString
();
matterResult
.
data
.
description
=
processedDescription
.
toString
();
}
}
// Combine the data with the id and contentHtml
// Combine the data with the id and contentHtml
return
{
return
{
id
,
id
:
getIdFromFileName
(
fileName
)
,
contentHtml
,
contentHtml
,
...
matterResult
.
data
,
...
matterResult
.
data
,
};
};
...
...
next/pages/poesie.js
View file @
ffcea4d1
...
@@ -18,7 +18,7 @@ export async function getStaticProps() {
...
@@ -18,7 +18,7 @@ export async function getStaticProps() {
export
default
function
Poems
({
poems
})
{
export
default
function
Poems
({
poems
})
{
const
[
sortBy
,
setSortBy
]
=
useState
(
'date'
);
const
[
sortBy
,
setSortBy
]
=
useState
(
'date'
);
const
[
sortOrder
,
setSortOrder
]
=
useState
(
'desc'
);
const
[
sortOrder
,
setSortOrder
]
=
useState
(
'desc'
);
const
[
filterLanguage
,
setFilterLanguage
]
=
useState
(
'
all'
);
const
[
filterLanguage
,
setFilterLanguage
]
=
useState
(
'
Français'
);
// Default language set to Français
const
[
filterTags
,
setFilterTags
]
=
useState
(
'all'
);
const
[
filterTags
,
setFilterTags
]
=
useState
(
'all'
);
// Get unique languages and tags
// Get unique languages and tags
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment