diff --git a/quartz/components/scripts/copypage.inline.ts b/quartz/components/scripts/copypage.inline.ts
index 7e57b8650..0003c6afb 100644
--- a/quartz/components/scripts/copypage.inline.ts
+++ b/quartz/components/scripts/copypage.inline.ts
@@ -3,20 +3,31 @@ const svgCopy =
const svgCheck =
''
+async function copyToClipboard(text: string): Promise {
+ try {
+ await navigator.clipboard.writeText(text)
+ return true
+ } catch {
+ // Fallback for mobile browsers
+ const textarea = Object.assign(document.createElement("textarea"), {
+ value: text,
+ style: "position:fixed;left:-9999px",
+ })
+ document.body.appendChild(textarea)
+ textarea.select()
+ const ok = document.execCommand("copy")
+ document.body.removeChild(textarea)
+ return ok
+ }
+}
+
async function copyPageMarkdown(slug: string): Promise {
try {
- // Use full blog content for home page, individual page content otherwise
const llmsUrl = slug === "index" ? `/llms-full.txt` : `/${slug}/llms.txt`
const response = await fetch(llmsUrl)
- if (!response.ok) {
- console.error("Failed to fetch markdown:", response.statusText)
- return false
- }
- const markdown = await response.text()
- await navigator.clipboard.writeText(markdown)
- return true
- } catch (error) {
- console.error("Failed to copy page markdown:", error)
+ if (!response.ok) return false
+ return copyToClipboard(await response.text())
+ } catch {
return false
}
}
@@ -112,3 +123,4 @@ document.addEventListener("nav", () => {
})
+