From e586d7d704d475afe3373a1de6ae20d504f79d6d Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 5 Jun 2025 14:25:23 +0000 Subject: Sync from a8e1c0a7402940e0fc5beef669522b315052df1b --- examples/hackernews/src/components/Comment.astro | 59 +++++++++++++ examples/hackernews/src/components/For.astro | 23 +++++ examples/hackernews/src/components/Nav.astro | 99 +++++++++++++++++++++ examples/hackernews/src/components/Show.astro | 9 ++ examples/hackernews/src/components/Story.astro | 77 +++++++++++++++++ examples/hackernews/src/components/Toggle.astro | 78 +++++++++++++++++ examples/hackernews/src/layouts/Layout.astro | 36 ++++++++ examples/hackernews/src/lib/api.ts | 24 ++++++ examples/hackernews/src/pages/[...stories].astro | 105 +++++++++++++++++++++++ examples/hackernews/src/pages/stories/[id].astro | 96 +++++++++++++++++++++ examples/hackernews/src/pages/users/[id].astro | 69 +++++++++++++++ examples/hackernews/src/types.ts | 27 ++++++ 12 files changed, 702 insertions(+) create mode 100644 examples/hackernews/src/components/Comment.astro create mode 100644 examples/hackernews/src/components/For.astro create mode 100644 examples/hackernews/src/components/Nav.astro create mode 100644 examples/hackernews/src/components/Show.astro create mode 100644 examples/hackernews/src/components/Story.astro create mode 100644 examples/hackernews/src/components/Toggle.astro create mode 100644 examples/hackernews/src/layouts/Layout.astro create mode 100644 examples/hackernews/src/lib/api.ts create mode 100644 examples/hackernews/src/pages/[...stories].astro create mode 100644 examples/hackernews/src/pages/stories/[id].astro create mode 100644 examples/hackernews/src/pages/users/[id].astro create mode 100644 examples/hackernews/src/types.ts (limited to 'examples/hackernews/src') diff --git a/examples/hackernews/src/components/Comment.astro b/examples/hackernews/src/components/Comment.astro new file mode 100644 index 000000000..07e55d19b --- /dev/null +++ b/examples/hackernews/src/components/Comment.astro @@ -0,0 +1,59 @@ +--- +import type { IComment } from '../types.js'; +import For from './For.astro'; +import Show from './Show.astro'; +import Toggle from './Toggle.astro'; + +interface Props { + comment: IComment; +} + +const { comment } = Astro.props; +--- + +
  • +
    + {comment.user}{' '} + {comment.time_ago} +
    +
    + + + {(comment: IComment) => } + + +
  • + + diff --git a/examples/hackernews/src/components/For.astro b/examples/hackernews/src/components/For.astro new file mode 100644 index 000000000..6eae88e27 --- /dev/null +++ b/examples/hackernews/src/components/For.astro @@ -0,0 +1,23 @@ +--- +import Show from './Show.astro'; + +interface Props { + each: Iterable; +} + +const { each } = Astro.props; +--- + +{ + (async function* () { + for await (const value of each) { + let html = await Astro.slots.render('default', [value]); + yield ; + yield '\n'; + } + })() +} + + + + diff --git a/examples/hackernews/src/components/Nav.astro b/examples/hackernews/src/components/Nav.astro new file mode 100644 index 000000000..7eeba2865 --- /dev/null +++ b/examples/hackernews/src/components/Nav.astro @@ -0,0 +1,99 @@ +--- +interface Link { + href: string; + text: string; +} + +const links: Link[] = [ + { href: '/', text: 'HN' }, + { href: '/new', text: 'New' }, + { href: '/show', text: 'Show' }, + { href: '/ask', text: 'Ask' }, + { href: '/job', text: 'Jobs' }, +]; +--- + +
    + +
    + + diff --git a/examples/hackernews/src/components/Show.astro b/examples/hackernews/src/components/Show.astro new file mode 100644 index 000000000..ccb642fd7 --- /dev/null +++ b/examples/hackernews/src/components/Show.astro @@ -0,0 +1,9 @@ +--- +interface Props { + when: T | number | boolean | undefined | null; +} + +const { when } = Astro.props; +--- + +{!!when ? : } diff --git a/examples/hackernews/src/components/Story.astro b/examples/hackernews/src/components/Story.astro new file mode 100644 index 000000000..e91748a30 --- /dev/null +++ b/examples/hackernews/src/components/Story.astro @@ -0,0 +1,77 @@ +--- +import type { IStory } from '../types.js'; +import Show from './Show.astro'; + +interface Props { + story: IStory; +} + +const { story } = Astro.props; +--- + +
  • + {story.points} + + + + {story.title} + + ({story.domain}) + {story.title} + + +
    + + + by {story.user}{' '} + {story.time_ago}{' '}|{' '} + + {story.comments_count ? `${story.comments_count} comments` : 'discuss'} + + {story.time_ago} + + + +   + {story.type} + +
  • + + diff --git a/examples/hackernews/src/components/Toggle.astro b/examples/hackernews/src/components/Toggle.astro new file mode 100644 index 000000000..799fca08c --- /dev/null +++ b/examples/hackernews/src/components/Toggle.astro @@ -0,0 +1,78 @@ +--- +interface Props { + open?: boolean; +} + +const { open = false } = Astro.props; +--- + + + +
      + +
    +
    + + + + diff --git a/examples/hackernews/src/layouts/Layout.astro b/examples/hackernews/src/layouts/Layout.astro new file mode 100644 index 000000000..47bc1ab1a --- /dev/null +++ b/examples/hackernews/src/layouts/Layout.astro @@ -0,0 +1,36 @@ +--- +import Nav from '../components/Nav.astro'; +--- + + + + + + + + Astro - Hacker News + + + +