@half-built/astro 0.4.2 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -24,6 +24,23 @@ wider preview concept (the blog's SHOW_DRAFTS builds, for example)
|
|
|
24
24
|
passes its own gate through the `shown` prop; the component reads no
|
|
25
25
|
consumer config itself.
|
|
26
26
|
|
|
27
|
+
## WhenPublished and PostLink
|
|
28
|
+
|
|
29
|
+
`content/WhenPublished.astro` renders its children only when the post
|
|
30
|
+
at `slug` is visible, so a published post can tease one still in
|
|
31
|
+
draft and the passage appears on its own when the target ships.
|
|
32
|
+
`content/PostLink.astro` links to a post by slug and resolves the
|
|
33
|
+
href at build time through `postPath`, so a re-dated post does not
|
|
34
|
+
strand the links pointing at it. Both take the consumer's collection
|
|
35
|
+
as the `posts` prop (the full collection, drafts included, so an
|
|
36
|
+
unknown slug can throw instead of hiding as "still a draft");
|
|
37
|
+
`WhenPublished` also takes the consumer's draft gate as `showDrafts`,
|
|
38
|
+
and `PostLink` accepts an optional `tip` carried as `data-tooltip` for
|
|
39
|
+
the link-tip island. A consumer wraps each in a one-line site
|
|
40
|
+
component that injects `getCollection` and its own gate, the way the
|
|
41
|
+
blog does. The resolvers live in `lib/drafts.ts` for consumers that
|
|
42
|
+
want the logic without the components.
|
|
43
|
+
|
|
27
44
|
## Live code colors
|
|
28
45
|
|
|
29
46
|
`shiki/code-theme` bakes its amber values into every highlighted span
|
package/package.json
CHANGED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
---
|
|
2
|
+
/* Internal link to a post, addressed by slug rather than by URL, so the
|
|
3
|
+
href follows the target if its date changes. Pairs with WhenPublished
|
|
4
|
+
for forward links: put the PostLink inside the wrapper and the
|
|
5
|
+
passage carries only the slug, twice, with nothing to keep in sync.
|
|
6
|
+
Moved up from the blog's content/PostLink.astro (owner call
|
|
7
|
+
2026-09-10); the resolver was already here in lib/drafts. The
|
|
8
|
+
consumer passes its collection, and may pass `tip`, the hover text
|
|
9
|
+
the link-tip island reads from data-tooltip. Resolves drafts as well
|
|
10
|
+
(it has to, see resolvePostHref); the deploy-build guard against a
|
|
11
|
+
bare link to a draft is a consumer test on the built pages. */
|
|
12
|
+
import { resolvePostHref, type Linkable } from "../../lib/drafts";
|
|
13
|
+
|
|
14
|
+
interface Props { slug: string; posts: Linkable[]; tip?: string; class?: string }
|
|
15
|
+
const { slug, posts, tip, class: className } = Astro.props;
|
|
16
|
+
const href = resolvePostHref(slug, posts);
|
|
17
|
+
---
|
|
18
|
+
<a href={href} data-tooltip={tip} class={className}><slot /></a>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
---
|
|
2
|
+
/* Forward-link gate: renders its children only when the post at `slug`
|
|
3
|
+
is visible in this build. A published post can tease a post that is
|
|
4
|
+
still a draft, and the passage appears on its own once the target
|
|
5
|
+
ships, with nothing to revise. Moved up from the blog's
|
|
6
|
+
content/WhenPublished.astro (owner call 2026-09-10); the logic was
|
|
7
|
+
already here in lib/drafts. The consumer passes its own collection
|
|
8
|
+
and its own draft gate, because a package component reads no
|
|
9
|
+
consumer content or config (the EditorNote precedent). Pass the
|
|
10
|
+
full collection, drafts included: the lookup has to tell "draft"
|
|
11
|
+
apart from "no such post", and the latter throws so a typo cannot
|
|
12
|
+
pass as "still a draft". Astro renders slot children eagerly, so a
|
|
13
|
+
PostLink inside a hidden passage still resolves; a consumer's guard
|
|
14
|
+
against a draft link leaking into a deploy build is a test on the
|
|
15
|
+
built pages, not this gate. */
|
|
16
|
+
import { forwardLinkVisible, type ForwardLinkable } from "../../lib/drafts";
|
|
17
|
+
|
|
18
|
+
interface Props { slug: string; posts: ForwardLinkable[]; showDrafts?: boolean }
|
|
19
|
+
const { slug, posts, showDrafts = false } = Astro.props;
|
|
20
|
+
const visible = forwardLinkVisible(slug, posts, showDrafts);
|
|
21
|
+
---
|
|
22
|
+
{visible && <slot />}
|