-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-content.js
More file actions
118 lines (100 loc) · 3.91 KB
/
test-content.js
File metadata and controls
118 lines (100 loc) · 3.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// Simple test to see what getAllPostsMeta() returns (ESM)
import fs from 'node:fs';
import path from 'node:path';
import matter from 'gray-matter';
const POSTS_DIR = path.join(process.cwd(), 'content', 'posts');
console.log('🔍 Testing content library functions...\n');
// Simulate what getPostFiles() does
function getPostFiles() {
if (!fs.existsSync(POSTS_DIR)) {
return [];
}
return fs.readdirSync(POSTS_DIR)
.filter(file => /\.mdx?$/.test(file))
.filter(file => {
// Filter out draft posts during static builds
if (process.env.NODE_ENV === 'production') {
try {
const filePath = path.join(POSTS_DIR, file);
const fileContent = fs.readFileSync(filePath, 'utf8');
const { data } = matter(fileContent);
// Only include posts where draft is explicitly false or undefined
return data.draft !== true;
} catch (error) {
// If there's an error reading the file, log it but include the post
console.warn(`Warning: Error reading post ${file}, including it anyway:`, error);
return true;
}
}
// In development, include all posts
return true;
})
.sort((a, b) => b.localeCompare(a));
}
// Simulate what getPostMeta() does
function getPostMeta(filename) {
const filePath = path.join(POSTS_DIR, filename);
const fileContent = fs.readFileSync(filePath, 'utf8');
const { data } = matter(fileContent);
// Generate slug from filename (simplified)
const slug = filename.replace(/\.mdx?$/, '');
return {
slug,
title: data.title,
date: data.date,
draft: data.draft
};
}
// Simulate what getAllPostsMeta() does
function getAllPostsMeta() {
const files = getPostFiles();
return files.map(getPostMeta);
}
// Test the functions
console.log('📁 Testing getPostFiles()...');
const postFiles = getPostFiles();
console.log(`Found ${postFiles.length} post files`);
// Check if our problematic post is in the list
const problematicFile = '2021-01-02-tools-for-effecting-rolls-in-dd.mdx';
const hasProblematicFile = postFiles.includes(problematicFile);
console.log(`\n🔍 Has problematic file '${problematicFile}': ${hasProblematicFile}`);
if (hasProblematicFile) {
console.log('✅ File found in getPostFiles()');
} else {
console.log('❌ File NOT found in getPostFiles()');
// Check what happened to it
const allFiles = fs.readdirSync(POSTS_DIR).filter(file => /\.mdx?$/.test(file));
const hasInAllFiles = allFiles.includes(problematicFile);
console.log(`\n🔍 File in all MDX files: ${hasInAllFiles}`);
if (hasInAllFiles) {
console.log('⚠️ File exists but was filtered out by getPostFiles()');
// Check why it was filtered
try {
const filePath = path.join(POSTS_DIR, problematicFile);
const fileContent = fs.readFileSync(filePath, 'utf8');
const { data } = matter(fileContent);
console.log(`📝 Draft status: ${data.draft}`);
console.log(`📝 Title: ${data.title}`);
console.log(`📝 Date: ${data.date}`);
} catch (error) {
console.log(`❌ Error reading file: ${error.message}`);
}
}
}
console.log('\n📊 Testing getAllPostsMeta()...');
const allPostsMeta = getAllPostsMeta();
console.log(`getAllPostsMeta() returned ${allPostsMeta.length} posts`);
// Check if our problematic post slug is in the metadata
const problematicSlug = 'tools-for-effecting-rolls-in-dd';
const hasProblematicSlug = allPostsMeta.some(post => post.slug === problematicSlug);
console.log(`\n🔍 Has problematic slug '${problematicSlug}': ${hasProblematicSlug}`);
if (hasProblematicSlug) {
console.log('✅ Slug found in getAllPostsMeta()');
} else {
console.log('❌ Slug NOT found in getAllPostsMeta()');
// Show what slugs we do have
console.log('\n📝 Available slugs (first 10):');
allPostsMeta.slice(0, 10).forEach((post, index) => {
console.log(`${index + 1}. ${post.slug} (${post.date})`);
});
}