mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-10-12 07:58:49 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6b7d177efe |
@@ -59,10 +59,8 @@ export default async function PDFHTMLOutput(props: {
|
|||||||
searchParams: Promise<{ [key: string]: string }>;
|
searchParams: Promise<{ [key: string]: string }>;
|
||||||
}) {
|
}) {
|
||||||
const pointer = await getSiteOrSpacePointerForPDF();
|
const pointer = await getSiteOrSpacePointerForPDF();
|
||||||
|
|
||||||
const searchParams = new URLSearchParams(await props.searchParams);
|
const searchParams = new URLSearchParams(await props.searchParams);
|
||||||
const pdfParams = getPDFSearchParams(new URLSearchParams(searchParams));
|
const pdfParams = getPDFSearchParams(new URLSearchParams(searchParams));
|
||||||
|
|
||||||
// Build current PDF URL and preserve all search params
|
// Build current PDF URL and preserve all search params
|
||||||
let currentPDFUrl = await getAbsoluteHref('~gitbook/pdf', true);
|
let currentPDFUrl = await getAbsoluteHref('~gitbook/pdf', true);
|
||||||
currentPDFUrl += '?' + searchParams.toString();
|
currentPDFUrl += '?' + searchParams.toString();
|
||||||
@@ -324,6 +322,16 @@ function selectPages(
|
|||||||
}),
|
}),
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
const range = (entries: FlatPageEntry[]) => {
|
||||||
|
if(params.from !== undefined && params.to) {
|
||||||
|
const sliced = entries.slice(params.from, params.to +1);
|
||||||
|
return {
|
||||||
|
pages: sliced,
|
||||||
|
total: params.to - params.from + 1,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return limitTo(entries)
|
||||||
|
}
|
||||||
|
|
||||||
const limitTo = (entries: FlatPageEntry[]) => {
|
const limitTo = (entries: FlatPageEntry[]) => {
|
||||||
return {
|
return {
|
||||||
@@ -332,7 +340,6 @@ function selectPages(
|
|||||||
total: entries.length,
|
total: entries.length,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
if (params.page) {
|
if (params.page) {
|
||||||
const found = resolvePageId(rootPages, params.page);
|
const found = resolvePageId(rootPages, params.page);
|
||||||
if (!found) {
|
if (!found) {
|
||||||
@@ -357,5 +364,5 @@ function selectPages(
|
|||||||
|
|
||||||
return flattenPage(page, 0);
|
return flattenPage(page, 0);
|
||||||
});
|
});
|
||||||
return limitTo(allPages);
|
return range(allPages);
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-7
@@ -221,13 +221,13 @@ export function cache<Args extends any[], Result>(
|
|||||||
|
|
||||||
// Log
|
// Log
|
||||||
if (process.env.SILENT !== 'true') {
|
if (process.env.SILENT !== 'true') {
|
||||||
console.log(
|
// //console.log(
|
||||||
`cache: ${key} ${cacheStatus}${
|
// `cache: ${key} ${cacheStatus}${
|
||||||
cacheStatus === 'hit' ? ` on ${backendName}` : ''
|
// cacheStatus === 'hit' ? ` on ${backendName}` : ''
|
||||||
} in total ${totalDuration.toFixed(0)}ms, fetch in ${fetchDuration.toFixed(
|
// } in total ${totalDuration.toFixed(0)}ms, fetch in ${fetchDuration.toFixed(
|
||||||
0,
|
// 0,
|
||||||
)}ms, read in ${readCacheDuration.toFixed(0)}ms`,
|
// )}ms, read in ${readCacheDuration.toFixed(0)}ms`,
|
||||||
);
|
// );
|
||||||
}
|
}
|
||||||
|
|
||||||
if (savedEntry.meta.revalidatesAt && savedEntry.meta.revalidatesAt < Date.now()) {
|
if (savedEntry.meta.revalidatesAt && savedEntry.meta.revalidatesAt < Date.now()) {
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ export async function trace<T>(
|
|||||||
} finally {
|
} finally {
|
||||||
if (process.env.SILENT !== 'true') {
|
if (process.env.SILENT !== 'true') {
|
||||||
let end = now();
|
let end = now();
|
||||||
console.log(`trace ${completeName} ${end - start}ms`, attributes);
|
//console.log(`trace ${completeName} ${end - start}ms`, attributes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ export interface PDFSearchParams {
|
|||||||
limit?: number;
|
limit?: number;
|
||||||
/** URL to redirect back to */
|
/** URL to redirect back to */
|
||||||
back?: string;
|
back?: string;
|
||||||
|
from?: number;
|
||||||
|
to?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -27,6 +29,12 @@ export function getPDFSearchParams(searchParams: URLSearchParams): PDFSearchPara
|
|||||||
if (searchParams.has('back')) {
|
if (searchParams.has('back')) {
|
||||||
params.back = searchParams.get('back') ?? '';
|
params.back = searchParams.get('back') ?? '';
|
||||||
}
|
}
|
||||||
|
if (searchParams.has('from')) {
|
||||||
|
params.from = Number(searchParams.get('from'));
|
||||||
|
}
|
||||||
|
if (searchParams.has('to')) {
|
||||||
|
params.to = Number(searchParams.get('to'));
|
||||||
|
}
|
||||||
|
|
||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user