Skip to content

Commit

Permalink
improved api
Browse files Browse the repository at this point in the history
  • Loading branch information
KishiTheMechanic committed Nov 4, 2024
1 parent 09bf982 commit 7dfb212
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 13 deletions.
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@elsoul/fresh-sitemap",
"version": "1.2.1",
"version": "1.3.0",
"description": "This plugin generates a sitemap for a Deno Fresh v2 project.",
"runtimes": ["deno", "browser"],
"exports": "./mod.ts",
Expand Down
41 changes: 29 additions & 12 deletions mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,24 @@ export interface SiteMapOptions {
defaultLanguage?: string
}

/**
* Configuration options for saving the sitemap and robots.txt.
*/
export interface SitemapConfig {
/** The base URL of the website (e.g., 'https://example.com') */
basename: string
/** Directory containing route files */
distDirectory: string
/** Directory containing posts in markdown format */
postsDirectory: string
/** Path to save the generated sitemap XML */
sitemapPath: string
/** Path to save the generated robots.txt */
robotsPath: string
/** Additional options for sitemap generation, including languages */
options?: SiteMapOptions
}

/**
* Generates a sitemap XML string from specified directories and a base URL.
* @param basename - The base URL of the website (e.g., 'https://example.com')
Expand Down Expand Up @@ -87,21 +105,20 @@ Sitemap: https://${domain}/sitemap.xml

/**
* Saves the generated sitemap XML and robots.txt files to specified file paths.
* @param basename - The base URL of the website
* @param distDirectory - The directory containing route files
* @param postsDirectory - The directory containing posts
* @param sitemapPath - Path where sitemap.xml will be saved
* @param robotsPath - Path where robots.txt will be saved
* @param options - Options for sitemap generation, including languages and default language
* @param config - Configuration object for sitemap and robots.txt generation
*/
export async function saveSitemapAndRobots(
basename: string,
distDirectory: string,
postsDirectory: string,
sitemapPath: string,
robotsPath: string,
options: SiteMapOptions = {},
config: SitemapConfig,
): Promise<void> {
const {
basename,
distDirectory,
postsDirectory,
sitemapPath,
robotsPath,
options = {},
} = config

const domain = new URL(basename).hostname
const sitemapXML = await generateSitemapXML(
basename,
Expand Down

0 comments on commit 7dfb212

Please sign in to comment.