mirror of
https://github.com/withastro/astro.git
synced 2024-12-16 21:46:22 -05:00
[ci] format
This commit is contained in:
parent
2f05f5d307
commit
65cc3f64f6
3 changed files with 29 additions and 22 deletions
|
@ -240,14 +240,21 @@ interface GeneratePathOptions {
|
|||
renderers: SSRLoadedRenderer[];
|
||||
}
|
||||
|
||||
function shouldAppendForwardSlash(trailingSlash: AstroConfig['trailingSlash'], buildFormat: AstroConfig['build']['format']): boolean {
|
||||
switch(trailingSlash) {
|
||||
case 'always': return true;
|
||||
case 'never': return false;
|
||||
function shouldAppendForwardSlash(
|
||||
trailingSlash: AstroConfig['trailingSlash'],
|
||||
buildFormat: AstroConfig['build']['format']
|
||||
): boolean {
|
||||
switch (trailingSlash) {
|
||||
case 'always':
|
||||
return true;
|
||||
case 'never':
|
||||
return false;
|
||||
case 'ignore': {
|
||||
switch(buildFormat) {
|
||||
case 'directory': return true;
|
||||
case 'file': return false;
|
||||
switch (buildFormat) {
|
||||
case 'directory':
|
||||
return true;
|
||||
case 'file':
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -256,9 +263,9 @@ function shouldAppendForwardSlash(trailingSlash: AstroConfig['trailingSlash'], b
|
|||
function addPageName(pathname: string, opts: StaticBuildOptions): void {
|
||||
const trailingSlash = opts.astroConfig.trailingSlash;
|
||||
const buildFormat = opts.astroConfig.build.format;
|
||||
const pageName = shouldAppendForwardSlash(trailingSlash, buildFormat) ?
|
||||
pathname.replace(/\/?$/, '/').replace(/^\//, '') :
|
||||
pathname.replace(/^\//, '')
|
||||
const pageName = shouldAppendForwardSlash(trailingSlash, buildFormat)
|
||||
? pathname.replace(/\/?$/, '/').replace(/^\//, '')
|
||||
: pathname.replace(/^\//, '');
|
||||
opts.pageNames.push(pageName);
|
||||
}
|
||||
|
||||
|
|
|
@ -19,12 +19,12 @@ export function loadFixture(inlineConfig) {
|
|||
|
||||
export function readXML(fileOrPromise) {
|
||||
const parseString = xml2js.parseString;
|
||||
return Promise.resolve(fileOrPromise).then(xml => {
|
||||
return Promise.resolve(fileOrPromise).then((xml) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
parseString(xml, function (err, result) {
|
||||
if(err) return reject(err);
|
||||
if (err) return reject(err);
|
||||
resolve(result);
|
||||
});
|
||||
});
|
||||
})
|
||||
});
|
||||
}
|
||||
|
|
|
@ -12,12 +12,12 @@ describe('Trailing slash', () => {
|
|||
root: './fixtures/trailing-slash/',
|
||||
trailingSlash: 'ignore',
|
||||
build: {
|
||||
format: 'directory'
|
||||
}
|
||||
format: 'directory',
|
||||
},
|
||||
});
|
||||
await fixture.build();
|
||||
});
|
||||
|
||||
|
||||
it('URLs end with trailing slash', async () => {
|
||||
const data = await readXML(fixture.readFile('/sitemap-0.xml'));
|
||||
const urls = data.urlset.url;
|
||||
|
@ -31,15 +31,15 @@ describe('Trailing slash', () => {
|
|||
root: './fixtures/trailing-slash/',
|
||||
trailingSlash: 'ignore',
|
||||
build: {
|
||||
format: 'file'
|
||||
}
|
||||
format: 'file',
|
||||
},
|
||||
});
|
||||
await fixture.build();
|
||||
});
|
||||
|
||||
|
||||
it('URLs do not end with trailing slash', async () => {
|
||||
const data = await readXML(fixture.readFile('/sitemap-0.xml'));
|
||||
const urls = data.urlset.url;
|
||||
const urls = data.urlset.url;
|
||||
expect(urls[0].loc[0]).to.equal('http://example.com/one');
|
||||
});
|
||||
});
|
||||
|
@ -53,7 +53,7 @@ describe('Trailing slash', () => {
|
|||
});
|
||||
await fixture.build();
|
||||
});
|
||||
|
||||
|
||||
it('URLs do no end with trailing slash', async () => {
|
||||
const data = await readXML(fixture.readFile('/sitemap-0.xml'));
|
||||
const urls = data.urlset.url;
|
||||
|
@ -69,7 +69,7 @@ describe('Trailing slash', () => {
|
|||
});
|
||||
await fixture.build();
|
||||
});
|
||||
|
||||
|
||||
it('URLs end with trailing slash', async () => {
|
||||
const data = await readXML(fixture.readFile('/sitemap-0.xml'));
|
||||
const urls = data.urlset.url;
|
||||
|
|
Loading…
Reference in a new issue