|
| 1 | +import { getAllArticlePaths, getArticleByPath } from './articleService'; |
| 2 | +import { getAllPosts } from './blogService'; |
| 3 | +import { getReferencesGroupedByTypeAndCategory, getAllReferenceParams, getReferenceByPath } from './referenceService'; |
| 4 | +import path from 'path'; |
| 5 | +import { Entity } from '../types/Entity'; |
| 6 | + |
| 7 | +export function getAllContent(): Entity[] { |
| 8 | + const pages: Entity[] = []; |
| 9 | + |
| 10 | + // 1. Home page |
| 11 | + pages.push({ |
| 12 | + url: '/', |
| 13 | + slug: 'home.png', |
| 14 | + title: 'DocumentDB', |
| 15 | + description: 'A powerful, scalable open-source document database solution', |
| 16 | + type: 'home', |
| 17 | + }); |
| 18 | + |
| 19 | + // 2. Docs landing |
| 20 | + pages.push({ |
| 21 | + url: '/docs', |
| 22 | + slug: 'docs.png', |
| 23 | + title: 'Documentation', |
| 24 | + description: 'Complete DocumentDB documentation and guides', |
| 25 | + section: 'docs', |
| 26 | + type: 'landing', |
| 27 | + }); |
| 28 | + |
| 29 | + // 3. All article/documentation pages |
| 30 | + const articlePaths = getAllArticlePaths(); |
| 31 | + for (const articlePath of articlePaths) { |
| 32 | + const article = getArticleByPath(articlePath.section, articlePath.slug); |
| 33 | + if (article) { |
| 34 | + const selectedNavItem = article.navigation.find((item: any) => |
| 35 | + item.link.includes(articlePath.slug[articlePath.slug.length - 1] || 'index') |
| 36 | + ); |
| 37 | + const title = article.frontmatter.title || selectedNavItem?.title || articlePath.section; |
| 38 | + |
| 39 | + let url = `/docs/${articlePath.section}`; |
| 40 | + if (articlePath.slug.length > 0) { |
| 41 | + url += `/${articlePath.slug.join('/')}`; |
| 42 | + } |
| 43 | + |
| 44 | + const mdFilePath = path.join( |
| 45 | + process.cwd(), |
| 46 | + 'articles', |
| 47 | + articlePath.section, |
| 48 | + ...articlePath.slug, |
| 49 | + 'index.md' |
| 50 | + ); |
| 51 | + |
| 52 | + // Convert URL to slug filename |
| 53 | + const slug = url === '/' |
| 54 | + ? 'home.png' |
| 55 | + : url.slice(1).replace(/\//g, '-') + '.png'; |
| 56 | + |
| 57 | + pages.push({ |
| 58 | + url, |
| 59 | + slug, |
| 60 | + title, |
| 61 | + description: article.frontmatter.description || `${title} - DocumentDB Documentation`, |
| 62 | + section: articlePath.section, |
| 63 | + type: 'docs', |
| 64 | + filePath: mdFilePath, |
| 65 | + }); |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | + // 4. Blogs landing |
| 70 | + pages.push({ |
| 71 | + url: '/blogs', |
| 72 | + slug: 'blogs.png', |
| 73 | + title: 'Blog', |
| 74 | + description: 'Latest insights and updates from DocumentDB', |
| 75 | + section: 'blog', |
| 76 | + type: 'landing', |
| 77 | + }); |
| 78 | + |
| 79 | + // 5. Individual blog posts (external URIs) |
| 80 | + const posts = getAllPosts(); |
| 81 | + for (const post of posts) { |
| 82 | + // Generate slug from title (for external blog posts without slugs) |
| 83 | + const slug = post.title |
| 84 | + .toLowerCase() |
| 85 | + .replace(/[^a-z0-9]+/g, '-') |
| 86 | + .replace(/^-+|-+$/g, ''); |
| 87 | + |
| 88 | + const url = `/blogs/${slug}`; |
| 89 | + const filename = url.slice(1).replace(/\//g, '-') + '.png'; |
| 90 | + |
| 91 | + pages.push({ |
| 92 | + url, |
| 93 | + slug: filename, |
| 94 | + title: post.title, |
| 95 | + description: post.description, |
| 96 | + section: 'blog', |
| 97 | + type: 'blog', |
| 98 | + isExternal: true, // Mark as external since these redirect to external URIs |
| 99 | + }); |
| 100 | + } |
| 101 | + |
| 102 | + // 6. Reference landing page |
| 103 | + pages.push({ |
| 104 | + url: '/docs/reference', |
| 105 | + slug: 'docs-reference.png', |
| 106 | + title: 'API Reference', |
| 107 | + description: 'Complete DocumentDB API reference documentation', |
| 108 | + section: 'reference', |
| 109 | + type: 'landing', |
| 110 | + }); |
| 111 | + |
| 112 | + // 7. Reference type pages (e.g., /docs/reference/commands) |
| 113 | + const referenceContent = getReferencesGroupedByTypeAndCategory(); |
| 114 | + for (const [type] of Object.entries(referenceContent)) { |
| 115 | + const url = `/docs/reference/${type}`; |
| 116 | + const slug = url.slice(1).replace(/\//g, '-') + '.png'; |
| 117 | + |
| 118 | + pages.push({ |
| 119 | + url, |
| 120 | + slug, |
| 121 | + title: `${type.charAt(0).toUpperCase() + type.slice(1)} Reference`, |
| 122 | + description: `DocumentDB ${type} reference documentation`, |
| 123 | + section: 'reference', |
| 124 | + type: 'landing', |
| 125 | + }); |
| 126 | + } |
| 127 | + |
| 128 | + // 8. Reference category pages (e.g., /docs/reference/operators/aggregation) |
| 129 | + for (const [type, categories] of Object.entries(referenceContent)) { |
| 130 | + for (const [category] of Object.entries(categories)) { |
| 131 | + const url = `/docs/reference/${type}/${category}`; |
| 132 | + const slug = url.slice(1).replace(/\//g, '-') + '.png'; |
| 133 | + |
| 134 | + pages.push({ |
| 135 | + url, |
| 136 | + slug, |
| 137 | + title: `${category} - ${type.charAt(0).toUpperCase() + type.slice(1)}`, |
| 138 | + description: `${category} ${type} reference documentation`, |
| 139 | + section: 'reference', |
| 140 | + type: 'landing', |
| 141 | + }); |
| 142 | + } |
| 143 | + } |
| 144 | + |
| 145 | + // 9. Individual reference items |
| 146 | + const referenceParams = getAllReferenceParams(); |
| 147 | + for (const param of referenceParams) { |
| 148 | + const reference = getReferenceByPath(param.type, param.category, param.name); |
| 149 | + if (reference) { |
| 150 | + const url = `/docs/reference/${param.type}/${param.category}/${param.name}`; |
| 151 | + const slug = url.slice(1).replace(/\//g, '-') + '.png'; |
| 152 | + |
| 153 | + const mdFilePath = path.join( |
| 154 | + process.cwd(), |
| 155 | + 'reference', |
| 156 | + param.type, |
| 157 | + param.category, |
| 158 | + `${param.name}.yml` |
| 159 | + ); |
| 160 | + |
| 161 | + pages.push({ |
| 162 | + url, |
| 163 | + slug, |
| 164 | + title: reference.name || param.name, |
| 165 | + description: reference.description || `${param.name} - DocumentDB Reference`, |
| 166 | + section: 'reference', |
| 167 | + type: 'reference', |
| 168 | + filePath: mdFilePath, |
| 169 | + }); |
| 170 | + } |
| 171 | + } |
| 172 | + |
| 173 | + // 10. Packages page |
| 174 | + pages.push({ |
| 175 | + url: '/packages', |
| 176 | + slug: 'packages.png', |
| 177 | + title: 'Packages', |
| 178 | + description: 'Download and install DocumentDB packages', |
| 179 | + type: 'packages', |
| 180 | + }); |
| 181 | + |
| 182 | + return pages; |
| 183 | +} |
0 commit comments