mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-10-23 05:35:25 +00:00
Better structure monorepo and publish JS files for react-openapi and react-math (#2392)
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
import psi from 'psi';
|
||||
|
||||
import { getContentTestURL, getTargetURL } from './utils';
|
||||
|
||||
interface Test {
|
||||
url: string;
|
||||
strategy: 'mobile' | 'desktop';
|
||||
threshold: number;
|
||||
}
|
||||
|
||||
const tests: Array<Test> = [
|
||||
{
|
||||
url: 'https://docs.gitbook.com',
|
||||
strategy: 'desktop',
|
||||
threshold: 90,
|
||||
},
|
||||
|
||||
{
|
||||
url: 'https://docs.gitbook.com',
|
||||
strategy: 'mobile',
|
||||
threshold: 80,
|
||||
},
|
||||
];
|
||||
|
||||
console.log(`Starting PageSpeed testing with ${getTargetURL()}...`);
|
||||
|
||||
for (const test of tests) {
|
||||
const url = getContentTestURL(test.url);
|
||||
|
||||
console.log(`Testing ${url} on ${test.strategy}...`);
|
||||
await psi.output(url, {
|
||||
strategy: test.strategy,
|
||||
threshold: test.threshold,
|
||||
key: process.env.PAGESPEED_API_KEY,
|
||||
});
|
||||
|
||||
console.log('');
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* Get the target URL from the command line arguments.
|
||||
*/
|
||||
export function getTargetURL() {
|
||||
const targetUrl = Bun.argv[2];
|
||||
if (!targetUrl) {
|
||||
console.error('No target URL provided');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
return targetUrl;
|
||||
}
|
||||
|
||||
export function getContentPathName(input: string): string {
|
||||
const contentUrl = new URL(input);
|
||||
return `${contentUrl.host}${contentUrl.pathname}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the URL to load for a content
|
||||
*/
|
||||
export function getContentTestURL(input: string, baseUrl: string = getTargetURL()): string {
|
||||
const url = new URL(baseUrl);
|
||||
const contentUrl = new URL(input);
|
||||
|
||||
url.pathname = `${contentUrl.host}${contentUrl.pathname}`;
|
||||
url.search = contentUrl.search;
|
||||
|
||||
return url.toString();
|
||||
}
|
||||
Reference in New Issue
Block a user