-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c68628e
commit 1bc6908
Showing
1 changed file
with
9 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { globToRegExp, join, normalize, SEPARATOR } from 'jsr:@std/[email protected]' | ||
import { ensureFile } from 'jsr:@std/[email protected]' | ||
import { ensureFile, exists } from 'jsr:@std/[email protected]' | ||
|
||
export interface SiteMapEntry { | ||
loc: string // URL location included in the <loc> tag | ||
|
@@ -119,6 +119,7 @@ async function generateSitemap( | |
|
||
/** | ||
* Generates sitemap entries for markdown articles, respecting language settings. | ||
* Checks if the articles directory exists before processing. | ||
* @param basename - The base URL | ||
* @param articlesDirectory - Directory containing article markdown files | ||
* @param options - Options for sitemap generation, including languages | ||
|
@@ -132,6 +133,11 @@ async function generateArticlesSitemap( | |
const sitemap: Sitemap = [] | ||
const languages = options.languages || [] | ||
|
||
// Check if articlesDirectory exists; if not, return an empty sitemap | ||
if (!(await exists(articlesDirectory))) { | ||
return sitemap | ||
} | ||
|
||
async function addMarkdownFile(path: string) { | ||
const relPath = path.substring(articlesDirectory.length).replace( | ||
/\.md$/, | ||
|
@@ -143,11 +149,8 @@ async function generateArticlesSitemap( | |
const pathname = normalize(`/${segments.join('/')}`).replace(/\/index$/, '') | ||
|
||
const urlPaths = languages.length > 0 | ||
? languages.map(( | ||
lang, | ||
) => (lang === options.defaultLanguage | ||
? pathname | ||
: `/${lang}${pathname}`) | ||
? languages.map((lang) => | ||
lang === options.defaultLanguage ? pathname : `/${lang}${pathname}` | ||
) | ||
: [pathname] | ||
|
||
|