| 1 |
--- |
| 2 |
/** |
| 3 |
* Split button for content pages: "Copy page" primary action, |
| 4 |
* with a chevron dropdown for secondary actions. |
| 5 |
* |
| 6 |
* The copy side fetches the page's `.md` companion (served by |
| 7 |
* pages/[...slug].md.ts) and writes it to the clipboard. |
| 8 |
* The dropdown uses the native Popover API for toggle + light-dismiss. |
| 9 |
*/ |
| 10 |
import type {ContentFile, ContentFolder} from '../lib/content'; |
| 11 |
|
| 12 |
interface Props { |
| 13 |
file: ContentFile | ContentFolder; |
| 14 |
} |
| 15 |
|
| 16 |
const {file} = Astro.props; |
| 17 |
const mdUrl = `${file.url}.md`; |
| 18 |
const popoverId = `page-actions-${file.slug}`; |
| 19 |
|
| 20 |
const pageItems = [ |
| 21 |
{ |
| 22 |
href: mdUrl, |
| 23 |
icon: 'icon-[mdi--language-markdown]', |
| 24 |
label: 'View as Markdown', |
| 25 |
description: 'Open this page as Markdown', |
| 26 |
}, |
| 27 |
]; |
| 28 |
|
| 29 |
const siteItems = [ |
| 30 |
{ |
| 31 |
href: '/llms.txt', |
| 32 |
icon: 'icon-[mdi--file-document]', |
| 33 |
label: 'llms.txt', |
| 34 |
description: 'htmx overview for LLMs', |
| 35 |
}, |
| 36 |
{ |
| 37 |
href: '/llms-full.txt', |
| 38 |
icon: 'icon-[mdi--file-document]', |
| 39 |
label: 'llms-full.txt', |
| 40 |
description: 'Complete htmx docs for LLMs', |
| 41 |
}, |
| 42 |
]; |
| 43 |
--- |
| 44 |
|
| 45 |
<div class="group/pop relative flex items-center"> |
| 46 |
<!-- Primary: Copy page --> |
| 47 |
<button |
| 48 |
class="group/copy flex items-center gap-2 |
| 49 |
px-3 py-1.5 |
| 50 |
rounded-l-lg border border-r-0 |
| 51 |
border-neutral-200 dark:border-neutral-800 |
| 52 |
text-neutral-600 dark:text-neutral-400 |
| 53 |
interact:bg-neutral-75 dark:interact:bg-neutral-875 |
| 54 |
interact:text-neutral-900 dark:interact:text-white |
| 55 |
outline-hidden cursor-pointer select-none" |
| 56 |
title="Copy page content as Markdown" |
| 57 |
_={`on click |
| 58 |
fetch ${mdUrl} as text then |
| 59 |
writeText(result) into navigator.clipboard |
| 60 |
add .icon-\\[radix-icons--check\\] to first <i/> in me |
| 61 |
remove .icon-\\[radix-icons--copy\\] from first <i/> in me |
| 62 |
put 'Copied!' into the first <span.label/> in me |
| 63 |
set @title of me to 'Copied!' |
| 64 |
add @data-copied to closest parent <div/> |
| 65 |
wait 2s |
| 66 |
add .icon-\\[radix-icons--copy\\] to first <i/> in me |
| 67 |
remove .icon-\\[radix-icons--check\\] from first <i/> in me |
| 68 |
put 'Copy page' into the first <span.label/> in me |
| 69 |
set @title of me to 'Copy page content' |
| 70 |
remove @data-copied from closest parent <div/>`}> |
| 71 |
<i class="size-3.5 icon-[radix-icons--copy]" aria-hidden="true"></i> |
| 72 |
<span class="label font-sans font-medium text-xs">Copy page</span> |
| 73 |
</button> |
| 74 |
|
| 75 |
<!-- Chevron: toggle popover --> |
| 76 |
<button |
| 77 |
class="group/chevron flex items-center justify-center |
| 78 |
w-7 self-stretch |
| 79 |
rounded-r-lg border |
| 80 |
border-neutral-200 dark:border-neutral-800 |
| 81 |
text-neutral-500 |
| 82 |
interact:bg-neutral-100 dark:interact:bg-neutral-875 |
| 83 |
interact:text-neutral-900 dark:interact:text-white |
| 84 |
outline-hidden cursor-pointer" |
| 85 |
aria-label="More actions" |
| 86 |
popovertarget={popoverId} |
| 87 |
style="anchor-name: --page-actions"> |
| 88 |
<i class="size-3 icon-[mdi--chevron-down] transition group-has-[:popover-open]/pop:rotate-180" |
| 89 |
aria-hidden="true"></i> |
| 90 |
</button> |
| 91 |
|
| 92 |
<!-- Dropdown menu (native popover) --> |
| 93 |
<div id={popoverId} |
| 94 |
popover="auto" |
| 95 |
style="position-anchor: --page-actions; top: anchor(bottom); right: anchor(right); left: auto; bottom: auto;" |
| 96 |
class="min-w-64 mt-1 p-1 |
| 97 |
rounded-xl border |
| 98 |
border-neutral-200 dark:border-neutral-800 |
| 99 |
bg-white dark:bg-neutral-930 |
| 100 |
shadow-xl shadow-neutral-900/5 dark:shadow-none"> |
| 101 |
|
| 102 |
<!-- This page --> |
| 103 |
{pageItems.map(item => ( |
| 104 |
<a href={item.href} |
| 105 |
target="_blank" |
| 106 |
rel="noopener noreferrer" |
| 107 |
class="group/item flex items-center gap-3 p-2 rounded-lg |
| 108 |
interact:bg-neutral-100 dark:interact:bg-neutral-850 |
| 109 |
cursor-pointer select-none"> |
| 110 |
<div class="border border-neutral-200 dark:border-neutral-800 group-hover/item:border-neutral-300 dark:group-hover/item:border-neutral-750 rounded-lg p-2 text-neutral-600 dark:text-neutral-400 group-hover/item:text-neutral-800 dark:group-hover/item:text-neutral-300"> |
| 111 |
<i class={`size-5 ${item.icon} block`} aria-hidden="true"></i> |
| 112 |
</div> |
| 113 |
<div class="flex flex-col gap-0.5 flex-1 min-w-0"> |
| 114 |
<span class="text-sm text-neutral-800 dark:text-neutral-300 group-hover/item:text-neutral-900 dark:group-hover/item:text-neutral-200 flex items-center gap-1"> |
| 115 |
{item.label} |
| 116 |
<i class="size-3 icon-[mdi--arrow-top-right] opacity-50 shrink-0" aria-hidden="true"></i> |
| 117 |
</span> |
| 118 |
<span class="text-xs font-light text-neutral-600 dark:text-neutral-400">{item.description}</span> |
| 119 |
</div> |
| 120 |
</a> |
| 121 |
))} |
| 122 |
|
| 123 |
<!-- Separator + site-wide section --> |
| 124 |
<div class="border-t border-neutral-200 dark:border-neutral-800 mt-1 pt-1"> |
| 125 |
<span class="block px-2 pt-2 pb-1.5 text-[0.625rem] font-medium uppercase tracking-wider text-neutral-600 dark:text-neutral-400"> |
| 126 |
For LLMs |
| 127 |
</span> |
| 128 |
{siteItems.map(item => ( |
| 129 |
<a href={item.href} |
| 130 |
target="_blank" |
| 131 |
rel="noopener noreferrer" |
| 132 |
class="group/item flex items-center gap-3 p-2 rounded-lg |
| 133 |
interact:bg-neutral-100 dark:interact:bg-neutral-850 |
| 134 |
cursor-pointer select-none"> |
| 135 |
<div class="border border-neutral-200 dark:border-neutral-800 group-hover/item:border-neutral-300 dark:group-hover/item:border-neutral-750 rounded-lg p-2 text-neutral-600 dark:text-neutral-400 group-hover/item:text-neutral-800 dark:group-hover/item:text-neutral-300"> |
| 136 |
<i class={`size-5 ${item.icon} block`} aria-hidden="true"></i> |
| 137 |
</div> |
| 138 |
<div class="flex flex-col gap-0.5 flex-1 min-w-0"> |
| 139 |
<span class="text-sm text-neutral-800 dark:text-neutral-300 group-hover/item:text-neutral-900 dark:group-hover/item:text-neutral-200 flex items-center gap-1"> |
| 140 |
{item.label} |
| 141 |
<i class="size-3 icon-[mdi--arrow-top-right] opacity-50 shrink-0" |
| 142 |
aria-hidden="true"></i> |
| 143 |
</span> |
| 144 |
<span class="text-xs font-light text-neutral-600 dark:text-neutral-400">{item.description}</span> |
| 145 |
</div> |
| 146 |
</a> |
| 147 |
))} |
| 148 |
</div> |
| 149 |
</div> |
| 150 |
</div> |
| 151 |
|