Skip to content

Commit 6826128

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

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 the ideal choice when you need:
25+
26+
- **Programmatic Generation**: Create documents dynamically using data and code
27+
- **Consistent Branding**: Maintain uniform styling across all documents through components
28+
- **Modern Development**: Leverage React, TypeScript, and the npm ecosystem
29+
- **CI/CD**: Push new document versions with CI/CD pipelines
30+
- **Version Control**: Track changes and collaborate using Git
31+
- **Developer-First**: Use familiar tools and workflows in a code-first environment
32+
33+
While traditional tools like Word or LaTeX have their place, htmldocs brings document creation into the modern web development ecosystem, offering powerful features for teams that need more than just basic word processing.

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)