-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(plugin-sitemap): added public files to sitemap
- Loading branch information
1 parent
aa61f30
commit 5a6bceb
Showing
4 changed files
with
95 additions
and
882 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { Origami } from '@origami/core'; | ||
import path from 'path'; | ||
// tslint:disable-next-line match-default-export-name | ||
import readdir from 'recursive-readdir'; | ||
import { SitemapItem } from '..'; | ||
|
||
/** | ||
* Publicly hosted directories | ||
* Load all html pages from public locations recursively | ||
*/ | ||
export const publicFiles = async ( | ||
config: Origami.Config | ||
): Promise<SitemapItem[] | false> => { | ||
let staticDir; | ||
if (config.server && config.server.static) staticDir = config.server.static; | ||
|
||
if (!staticDir || staticDir === true) staticDir = 'public'; | ||
if (!(staticDir instanceof Array)) staticDir = [staticDir]; | ||
|
||
let items: SitemapItem[] = []; | ||
|
||
await Promise.all(staticDir.map(async (d) => { | ||
const dir = path.resolve(process.cwd(), d); | ||
|
||
items = items.concat(await Promise.all( | ||
(await readdir(dir)) | ||
// Remove non html files | ||
.filter((f) => f.endsWith('.html')) | ||
// Convert to SitemapItem | ||
.map(async (f) => { | ||
// Remove HTML extension | ||
let url = path.relative(dir, f).slice(0, '.html'.length * -1); | ||
// Remove the /index | ||
if (url.endsWith('index')) url = url.slice(0, 'index'.length * -1); | ||
|
||
return { | ||
url: `/${url}`, | ||
changeFreq: 'daily', | ||
lastmodfile: f | ||
} as SitemapItem; | ||
}) | ||
)); | ||
})); | ||
|
||
return items; | ||
}; |
Oops, something went wrong.