-
-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fix] Index sitemap does not reference the generated sitemaps
Fix: #301
- Loading branch information
1 parent
ae7d182
commit 4e09807
Showing
5 changed files
with
64 additions
and
36 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
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
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
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,21 +1,45 @@ | ||
import { IConfig, IRuntimePaths } from '../../interface' | ||
import { INextSitemapResult } from '../../interface' | ||
import { generateRobotsTxt } from '../generate' | ||
import { exportFile } from '../../file' | ||
import { IConfig } from '../..' | ||
import { merge } from '@corex/deepmerge' | ||
|
||
export const getRobotsTxtExportConfig = ( | ||
config: IConfig, | ||
result: INextSitemapResult | ||
) => { | ||
return merge([ | ||
{ | ||
robotsTxtOptions: { | ||
additionalSitemaps: [ | ||
result?.runtimePaths?.SITEMAP_INDEX_URL, // URL of index sitemap | ||
...(config?.robotsTxtOptions?.includeNonIndexSitemaps // Optionally include static generated sitemap files | ||
? result?.generatedSitemaps ?? [] | ||
: []), | ||
], | ||
}, | ||
}, | ||
config, | ||
]) | ||
} | ||
|
||
/** | ||
* Export robots txt file | ||
* @param runtimePaths | ||
* @param config | ||
*/ | ||
export const exportRobotsTxt = async ( | ||
runtimePaths: IRuntimePaths, | ||
config: IConfig | ||
config: IConfig, | ||
result: INextSitemapResult | ||
): Promise<any> => { | ||
// Create a config specific for robots.txt | ||
const exportConfig = getRobotsTxtExportConfig(config, result) | ||
|
||
// Generate robots text | ||
const robotsTxt = generateRobotsTxt(config) | ||
const robotsTxt = generateRobotsTxt(exportConfig) | ||
|
||
// Create file | ||
if (robotsTxt) { | ||
await exportFile(runtimePaths.ROBOTS_TXT_FILE, robotsTxt) | ||
await exportFile(result?.runtimePaths.ROBOTS_TXT_FILE, robotsTxt) | ||
} | ||
} |
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