File size: 1,067 Bytes
9316888
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';

const currentFile = fileURLToPath(import.meta.url);
const __dirname = path.dirname(currentFile);
const projectRoot = path.resolve(__dirname, '..');

export const seoContentDir = path.resolve(projectRoot, 'seo', 'content');

export function normalizeRouteFromMarkdown(relativePath) {
  const normalized = relativePath
    .replace(/\\/g, '/')
    .replace(/\/index\.md$/, '')
    .replace(/\.md$/, '');

  return normalized ? `/blog/${normalized}/` : '/blog/';
}

export function collectMarkdownFiles(dir, bucket = []) {
  if (!fs.existsSync(dir)) {
    return bucket;
  }

  for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
    if (entry.name.startsWith('.')) {
      continue;
    }

    const fullPath = path.join(dir, entry.name);
    if (entry.isDirectory()) {
      collectMarkdownFiles(fullPath, bucket);
      continue;
    }

    if (entry.isFile() && entry.name.endsWith('.md')) {
      bucket.push(fullPath);
    }
  }

  return bucket;
}