Skip to content

Commit 19b8350

Browse files
committed
error handling on generation, comparison docs
1 parent beede93 commit 19b8350

File tree

5 files changed

+8411
-2242
lines changed

5 files changed

+8411
-2242
lines changed

apps/docs/comparison.mdx

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
title: "Comparing htmldocs"
3+
description: "See how htmldocs compares to other document creation solutions"
4+
icon: "code-compare"
5+
---
6+
7+
8+
| Feature | Traditional Documents<br/>(Word, Google Docs) | LaTeX Documents<br/>(Overleaf, TeXStudio) | Freeform Documents<br/>(Figma, Sketch) | Web Documents<br/>(htmldocs) |
9+
|---------|:-------------------------------------------:|:----------------------------------------:|:-------------------------------------:|:---------------------------:|
10+
| Learning Curve | ✅ Simple | ❌ Complex | ✅ Simple | ✅ Simple |
11+
| Template Variables | ❌ Limited | ❌ Limited | ❌ Limited | ✅ Supported |
12+
| Styling | ✅ Basic | ❌ Complex | ✅ Advanced | ✅ Advanced |
13+
| Version Control | ❌ Limited | ✅ Supported | ❌ Limited | ✅ Supported |
14+
| Document Consistency | ❌ Limited | ✅ Supported | ✅ Supported | ✅ Supported |
15+
| External Libraries | ❌ Limited | ✅ Supported | ❌ Limited | ✅ Supported |
16+
| Automation / API | ❌ Limited | ❌ Limited | ❌ Limited | ✅ Supported |
17+
| Developer Plugins | ❌ Limited | ❌ Limited | ❌ Limited | ✅ Supported |
18+
| Live Preview | ✅ Supported | ❌ Limited | ✅ Supported | ✅ Supported |
19+
| CI/CD Integration | ❌ Limited | ⚠️ Partial | ❌ Limited | ✅ Supported |
20+
| Type Safety | ❌ Limited | ❌ Limited | ❌ Limited | ✅ Supported |
21+
22+
## When to Choose htmldocs
23+
24+
htmldocs is ideal when you need:
25+
26+
- **Programmatic Generation**: You need to generate documents from your app's data
27+
- **Consistent Branding**: You're tired of manually updating Word templates
28+
- **Modern Development**: You want to use React components for documents
29+
- **Automation**: Your CI/CD pipeline needs to generate documents
30+
- **Version Control**: You want Git-based change tracking for documents
31+
- **Developer-First**: You prefer writing code over using WYSIWYG editors
32+
33+
Word and LaTeX are solid choices for static documents. But if you need to programmatically create documents as part of your application, htmldocs lets you do it with the tools you already know and love.

apps/docs/mint.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"group": "Overview",
5151
"pages": [
5252
"introduction",
53+
"comparison",
5354
"getting-started",
5455
"cli"
5556
]

packages/htmldocs/src/app/components/topbar.tsx

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Sidebar } from "@phosphor-icons/react";
44
import { Button } from "./ui/button";
55
import { useDocuments } from "~/contexts/documents";
66
import ContextEditorModal from "./context-editor-modal";
7+
import { toast } from "sonner";
78

89
interface TopbarProps {
910
documentPath: string;
@@ -30,22 +31,23 @@ export const Topbar: React.FC<Readonly<TopbarProps>> = ({
3031

3132
const renderAndDownloadPDF = async () => {
3233
if (!markup) {
33-
console.error("No markup available to generate PDF");
34+
toast.error("No markup available to generate PDF");
3435
return;
3536
}
3637

3738
setIsDownloading(true);
3839

39-
const pdfBuffer = await renderDocumentToPDF({
40-
url: window.location.href,
41-
html: markup,
42-
pageConfig: pageConfigs[documentPath]
43-
});
44-
45-
if (pdfBuffer instanceof Error) {
46-
console.error("Error downloading document:", pdfBuffer.message);
47-
setIsDownloading(false);
48-
} else {
40+
try {
41+
const pdfBuffer = await renderDocumentToPDF({
42+
url: window.location.href,
43+
html: markup,
44+
pageConfig: pageConfigs[documentPath]
45+
});
46+
47+
if (pdfBuffer instanceof Error) {
48+
throw pdfBuffer;
49+
}
50+
4951
// Ensure the buffer is in the correct type
5052
const buffer = new Uint8Array(pdfBuffer);
5153
const blob = new Blob([buffer], { type: "application/pdf" });
@@ -57,6 +59,11 @@ export const Topbar: React.FC<Readonly<TopbarProps>> = ({
5759
a.click();
5860
document.body.removeChild(a);
5961
window.URL.revokeObjectURL(downloadUrl);
62+
toast.success("PDF downloaded successfully");
63+
} catch (error) {
64+
console.error("Error downloading document:", error);
65+
toast.error("Failed to generate PDF. Check the CLI logs for more details.");
66+
} finally {
6067
setIsDownloading(false);
6168
}
6269
};

packages/htmldocs/src/app/preview/[...slug]/preview.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ const Preview = ({
263263
<ZoomControls />
264264
</div>
265265
) : null}
266-
<Toaster />
266+
<Toaster richColors />
267267
</div>
268268
</Shell>
269269
</DocumentContextProvider>

0 commit comments

Comments
 (0)