diff --git a/package.json b/package.json index 4ae1026..26cd758 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "version": "3.2.1", "main": "./dist/index.js", "scripts": { + "build:example": "npx amagaki build example", "check": "gts check", "clean": "gts clean", "compile": "tsc; npx gulp build;", diff --git a/src/sitemap.test.ts b/src/sitemap.test.ts index e4ef1f7..1c85511 100644 --- a/src/sitemap.test.ts +++ b/src/sitemap.test.ts @@ -8,23 +8,23 @@ test('SitemapPlugin: sitemap.xml', async (t: ExecutionContext) => { await pod.router.warmup(); const sitemapRoute = await pod.router.resolve('/foo/sitemap.xml') as Route; const sitemapContent = await sitemapRoute.build(); - const sitemapExpected = ` - - - - http://localhost/pages/foo/ - - - - - - http://localhost/pages/ - - - - - - `.trim(); + const sitemapExpected = +` + + + http://localhost/pages/foo/ + + + + + + http://localhost/pages/ + + + + + +`.trim(); t.deepEqual(sitemapContent, sitemapExpected); }); @@ -33,9 +33,6 @@ test('SitemapPlugin: robots.txt', async (t: ExecutionContext) => { await pod.router.warmup(); const robotsRoute = await pod.router.resolve('/bar/robots.txt') as Route; const robotsContent = await robotsRoute.build(); - const robotsExpected = ` - User-agent: * - Allow: / - `; + const robotsExpected = 'User-agent: *\nAllow: /'; t.deepEqual(robotsContent, robotsExpected); }); diff --git a/src/sitemap.ts b/src/sitemap.ts index 8fc9f0c..f5bfdee 100644 --- a/src/sitemap.ts +++ b/src/sitemap.ts @@ -5,6 +5,7 @@ import { RouteProvider, Router, } from '@amagaki/amagaki'; +import jsBeautify from 'js-beautify'; export interface SitemapPluginOptions { sitemapPath?: string; @@ -45,10 +46,7 @@ class RobotsTxtRoute extends Route { async build() { // TODO: Add Sitemap property, hook into document. - return ` - User-agent: * - Allow: / - `; + return 'User-agent: *\nAllow: /'; } } @@ -89,11 +87,12 @@ class SitemapRoute extends Route { (route as DocumentRoute).locale === this.pod.defaultLocale && !route.urlPath.includes('/404/') ); - return ( + const text = ( await njk.renderFromString(this.templateSource, { routes: routes, pod: this.pod, }) ).replace(/^\s*[\r\n]/gm, ''); + return jsBeautify.html(text, {indent_size: 2}); } }