-
-
Notifications
You must be signed in to change notification settings - Fork 114
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
4baf1b2
commit 30d2b36
Showing
7 changed files
with
83 additions
and
86 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,2 +1,2 @@ | ||
#!/usr/bin/env node | ||
require('../dist/cjs') | ||
require('../dist/cjs/cli') |
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* eslint-disable @typescript-eslint/no-non-null-assertion */ | ||
import { loadConfig, getRuntimeConfig, updateConfig } from './config' | ||
import { loadManifest } from './manifest' | ||
import { createUrlSet, generateUrl } from './url' | ||
import { generateSitemap } from './sitemap/generateSitemap' | ||
import { toChunks } from './array' | ||
import { | ||
resolveSitemapChunks, | ||
getRuntimePaths, | ||
getConfigFilePath, | ||
} from './path' | ||
import { exportRobotsTxt } from './robots-txt' | ||
|
||
// Get config file path | ||
const configFilePath = getConfigFilePath() | ||
|
||
// Load next-sitemap.js | ||
let config = loadConfig(configFilePath) | ||
|
||
// Get runtime paths | ||
const runtimePaths = getRuntimePaths(config) | ||
|
||
// get runtime config | ||
const runtimeConfig = getRuntimeConfig(runtimePaths) | ||
|
||
// Update config with runtime config | ||
config = updateConfig(config, runtimeConfig) | ||
|
||
// Load next.js manifest files | ||
const manifest = loadManifest(runtimePaths) | ||
|
||
// Create url-set based on config and manifest | ||
const urlSet = createUrlSet(config, manifest) | ||
|
||
// Split sitemap into multiple files | ||
const chunks = toChunks(urlSet, config.sitemapSize!) | ||
const sitemapChunks = resolveSitemapChunks(runtimePaths.SITEMAP_FILE, chunks) | ||
|
||
// All sitemaps array to keep track of generated sitemap files. | ||
// Later to be added on robots.txt | ||
const allSitemaps: string[] = [] | ||
|
||
// Generate sitemaps from chunks | ||
sitemapChunks.forEach((chunk) => { | ||
generateSitemap(chunk) | ||
allSitemaps.push(generateUrl(config.siteUrl, `/${chunk.filename}`)) | ||
}) | ||
|
||
// Generate robots.txt | ||
if (config.generateRobotsTxt) { | ||
exportRobotsTxt(runtimePaths, config, allSitemaps) | ||
} |
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,52 +1 @@ | ||
/* eslint-disable @typescript-eslint/no-non-null-assertion */ | ||
import { loadConfig, getRuntimeConfig, updateConfig } from './config' | ||
import { loadManifest } from './manifest' | ||
import { createUrlSet, generateUrl } from './url' | ||
import { generateSitemap } from './sitemap' | ||
import { toChunks } from './array' | ||
import { | ||
resolveSitemapChunks, | ||
getRuntimePaths, | ||
getConfigFilePath, | ||
} from './path' | ||
import { exportRobotsTxt } from './robots-txt' | ||
|
||
// Get config file path | ||
const configFilePath = getConfigFilePath() | ||
|
||
// Load next-sitemap.js | ||
let config = loadConfig(configFilePath) | ||
|
||
// Get runtime paths | ||
const runtimePaths = getRuntimePaths(config) | ||
|
||
// get runtime config | ||
const runtimeConfig = getRuntimeConfig(runtimePaths) | ||
|
||
// Update config with runtime config | ||
config = updateConfig(config, runtimeConfig) | ||
|
||
// Load next.js manifest files | ||
const manifest = loadManifest(runtimePaths) | ||
|
||
// Create url-set based on config and manifest | ||
const urlSet = createUrlSet(config, manifest) | ||
|
||
// Split sitemap into multiple files | ||
const chunks = toChunks(urlSet, config.sitemapSize!) | ||
const sitemapChunks = resolveSitemapChunks(runtimePaths.SITEMAP_FILE, chunks) | ||
|
||
// All sitemaps array to keep track of generated sitemap files. | ||
// Later to be added on robots.txt | ||
const allSitemaps: string[] = [] | ||
|
||
// Generate sitemaps from chunks | ||
sitemapChunks.forEach((chunk) => { | ||
generateSitemap(config, chunk.path, chunk.fields) | ||
allSitemaps.push(generateUrl(config.siteUrl, `/${chunk.filename}`)) | ||
}) | ||
|
||
// Generate robots.txt | ||
if (config.generateRobotsTxt) { | ||
exportRobotsTxt(runtimePaths, config, allSitemaps) | ||
} | ||
export * from './sitemap/buildSitemapXml' |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { ISitemapFiled } from '../interface' | ||
import { withXMLTemplate } from './withXMLTemplate' | ||
|
||
export const buildSitemapXml = (fields: ISitemapFiled[]): string => { | ||
const content = fields.reduce((prev, curr) => { | ||
let field = '' | ||
for (const key of Object.keys(curr)) { | ||
field += `<${key}>${curr[key]}</${key}>` | ||
} | ||
|
||
// Append previous value and return | ||
return `${prev}<url>${field}</url>\n` | ||
}, '') | ||
|
||
return withXMLTemplate(content) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { ISitemapChunk } from '../interface' | ||
import { exportFile } from '../file' | ||
import { buildSitemapXml } from './buildSitemapXml' | ||
|
||
export const generateSitemap = (chunk: ISitemapChunk): void => { | ||
const sitemapXml = buildSitemapXml(chunk.fields) | ||
exportFile(chunk.path, sitemapXml) | ||
} |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/* eslint-disable @typescript-eslint/no-non-null-assertion */ | ||
|
||
export const withXMLTemplate = (content: string): string => { | ||
return `<?xml version="1.0" encoding="UTF-8"?>\n<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">\n${content}</urlset>` | ||
} |