Let users extend the limit of PDF generation (#313)

* Add link to extend PDF generation limit

* Translate

* Use variable
This commit is contained in:
Samy Pessé
2024-03-20 17:49:28 +00:00
committed by GitHub
parent dc2d50e455
commit 0ad7bf561e
7 changed files with 31 additions and 12 deletions
@@ -9,6 +9,8 @@ import { t, useLanguage } from '@/intl/client';
import { tcls } from '@/lib/tailwind';
import { getPDFUrl } from '@/lib/urls';
const limitExtend = 50;
/**
* Dynamic controls to show active page and to let the user select between modes.
*/
@@ -17,12 +19,14 @@ export function PageControlButtons(props: {
singlePageMode: boolean;
/** Array of the [pageId, divId] */
pageIds: Array<[string, string]>;
/** Current limit */
limit: number;
/** Total number of pages targetted by the generation */
total: number;
/** Trademark to display */
trademark?: React.ReactNode;
}) {
const { pdfHref, singlePageMode, pageIds, total, trademark } = props;
const { pdfHref, singlePageMode, pageIds, limit, total, trademark } = props;
const language = useLanguage();
@@ -102,7 +106,21 @@ export function PageControlButtons(props: {
)}
>
<AlertTriangle className={tcls('size-6', 'mr-3', 'mt-1')} />{' '}
{t(language, 'pdf_limit_reached', total, pageIds.length)}
<div>
<div>{t(language, 'pdf_limit_reached', total, pageIds.length)}</div>
<div>
<a
href={getPDFUrl(new URL(pdfHref), {
page: undefined,
only: false,
limit: limit + limitExtend,
}).toString()}
className={tcls('underline')}
>
{t(language, 'pdf_limit_reached_continue', limitExtend)}
</a>
</div>
</div>
</div>
) : null}
<div
+6 -10
View File
@@ -16,14 +16,7 @@ import { TrademarkLink } from '@/components/TableOfContents/Trademark';
import { PolymorphicComponentProp } from '@/components/utils/types';
import { getSpaceLanguage } from '@/intl/server';
import { tString } from '@/intl/translate';
import {
getDocument,
getSpace,
getRevisionPages,
ContentPointer,
getSpaceCustomization,
getSpaceContentData,
} from '@/lib/api';
import { getDocument, getSpace, getSpaceCustomization, getSpaceContentData } from '@/lib/api';
import { pagePDFContainerId, PageHrefContext, absoluteHref } from '@/lib/links';
import { resolvePageId } from '@/lib/pages';
import { ContentRefContext, resolveContentRef } from '@/lib/references';
@@ -34,6 +27,8 @@ import './pdf.css';
import { PageControlButtons } from './PageControlButtons';
import { PrintButton } from './PrintButton';
const DEFAULT_LIMIT = 100;
export const runtime = 'edge';
export async function generateMetadata(): Promise<Metadata> {
@@ -138,6 +133,7 @@ export default async function PDFHTMLOutput(props: { searchParams: { [key: strin
pdfHref={currentPDFUrl}
singlePageMode={!!pdfParams.only}
total={total}
limit={pdfParams.limit ?? DEFAULT_LIMIT}
trademark={
customization.trademark.enabled ? (
<TrademarkLink space={space} customization={customization} />
@@ -146,7 +142,7 @@ export default async function PDFHTMLOutput(props: { searchParams: { [key: strin
/>
{pdfParams.only ? null : <PDFSpaceIntro space={space} customization={customization} />}
{pages.map(({ page, depth }) =>
{pages.map(({ page }) =>
page.type === 'group' ? (
<PDFPageGroup key={page.id} space={space} page={page} />
) : (
@@ -309,7 +305,7 @@ function selectPages(
const limitTo = (entries: FlatPageEntry[]) => {
return {
// Apply a soft-limit, the limit can be controlled by the URL to allow testing
pages: entries.slice(0, params.limit ?? 100),
pages: entries.slice(0, params.limit ?? DEFAULT_LIMIT),
total: entries.length,
};
};
+1
View File
@@ -48,4 +48,5 @@ export const en = {
pdf_mode_only_page: 'Only this page',
pdf_mode_all: 'All pages',
pdf_limit_reached: "Couldn't generate the PDF for ${1} pages, generation stopped at ${2}.",
pdf_limit_reached_continue: 'Extend with ${1} more pages.',
};
+1
View File
@@ -52,4 +52,5 @@ export const es: TranslationLanguage = {
pdf_mode_all: 'Todas las páginas',
pdf_limit_reached:
'No se pudo generar el PDF para ${1} páginas, la generación se detuvo en ${2}.',
pdf_limit_reached_continue: 'Extender con ${1} páginas más.',
};
+1
View File
@@ -50,4 +50,5 @@ export const fr: TranslationLanguage = {
pdf_mode_only_page: 'Seulement cette page',
pdf_mode_all: 'Toutes les pages',
pdf_limit_reached: 'Impossible de générer le PDF pour ${1} pages, génération arrêtée à ${2}.',
pdf_limit_reached_continue: 'Étendre avec ${1} pages supplémentaires.',
};
+1
View File
@@ -51,4 +51,5 @@ export const ja: TranslationLanguage = {
pdf_mode_only_page: 'このページのみ',
pdf_mode_all: '全てのページ',
pdf_limit_reached: '${1}ページのPDFを生成できませんでした、${2}で生成が停止しました。',
pdf_limit_reached_continue: 'さらに${1}ページで拡張',
};
+1
View File
@@ -49,4 +49,5 @@ export const zh: TranslationLanguage = {
pdf_mode_only_page: '仅本页',
pdf_mode_all: '所有页面',
pdf_limit_reached: '无法为${1}页生成 PDF,生成在${2}页时停止。',
pdf_limit_reached_continue: '使用${1}页进行扩展。',
};