Commit ffcea4d1 by PLN (Algolia)

fix: Filter, default poem fr

parent a4365692
...@@ -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);
const id = fileName.replace(/\.md$/, ""); console.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,
}; };
......
...@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment