0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-16 21:46:22 -05:00

[ci] format

This commit is contained in:
matthewp 2022-08-30 15:47:42 +00:00 committed by fredkbot
parent 2f05f5d307
commit 65cc3f64f6
3 changed files with 29 additions and 22 deletions

View file

@ -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);
}

View file

@ -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);
});
})
});
});
}

View file

@ -12,8 +12,8 @@ describe('Trailing slash', () => {
root: './fixtures/trailing-slash/',
trailingSlash: 'ignore',
build: {
format: 'directory'
}
format: 'directory',
},
});
await fixture.build();
});
@ -31,8 +31,8 @@ describe('Trailing slash', () => {
root: './fixtures/trailing-slash/',
trailingSlash: 'ignore',
build: {
format: 'file'
}
format: 'file',
},
});
await fixture.build();
});