mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-13 06:09:21 +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 }>;
|
||||
}) {
|
||||
const pointer = await getSiteOrSpacePointerForPDF();
|
||||
|
||||
const searchParams = new URLSearchParams(await props.searchParams);
|
||||
const pdfParams = getPDFSearchParams(new URLSearchParams(searchParams));
|
||||
|
||||
// Build current PDF URL and preserve all search params
|
||||
let currentPDFUrl = await getAbsoluteHref('~gitbook/pdf', true);
|
||||
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[]) => {
|
||||
return {
|
||||
@@ -332,7 +340,6 @@ function selectPages(
|
||||
total: entries.length,
|
||||
};
|
||||
};
|
||||
|
||||
if (params.page) {
|
||||
const found = resolvePageId(rootPages, params.page);
|
||||
if (!found) {
|
||||
@@ -357,5 +364,5 @@ function selectPages(
|
||||
|
||||
return flattenPage(page, 0);
|
||||
});
|
||||
return limitTo(allPages);
|
||||
return range(allPages);
|
||||
}
|
||||
|
||||
+7
-7
@@ -221,13 +221,13 @@ export function cache<Args extends any[], Result>(
|
||||
|
||||
// Log
|
||||
if (process.env.SILENT !== 'true') {
|
||||
console.log(
|
||||
`cache: ${key} ${cacheStatus}${
|
||||
cacheStatus === 'hit' ? ` on ${backendName}` : ''
|
||||
} in total ${totalDuration.toFixed(0)}ms, fetch in ${fetchDuration.toFixed(
|
||||
0,
|
||||
)}ms, read in ${readCacheDuration.toFixed(0)}ms`,
|
||||
);
|
||||
// //console.log(
|
||||
// `cache: ${key} ${cacheStatus}${
|
||||
// cacheStatus === 'hit' ? ` on ${backendName}` : ''
|
||||
// } in total ${totalDuration.toFixed(0)}ms, fetch in ${fetchDuration.toFixed(
|
||||
// 0,
|
||||
// )}ms, read in ${readCacheDuration.toFixed(0)}ms`,
|
||||
// );
|
||||
}
|
||||
|
||||
if (savedEntry.meta.revalidatesAt && savedEntry.meta.revalidatesAt < Date.now()) {
|
||||
|
||||
@@ -45,7 +45,7 @@ export async function trace<T>(
|
||||
} finally {
|
||||
if (process.env.SILENT !== 'true') {
|
||||
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;
|
||||
/** URL to redirect back to */
|
||||
back?: string;
|
||||
from?: number;
|
||||
to?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -27,6 +29,12 @@ export function getPDFSearchParams(searchParams: URLSearchParams): PDFSearchPara
|
||||
if (searchParams.has('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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user