Skip to content

Commit a24075f

Browse files
committed
add github pages example
1 parent 4f019cf commit a24075f

File tree

7 files changed

+83
-21
lines changed

7 files changed

+83
-21
lines changed

.github/workflows/deploy.yml

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# https://github.com/actions/deploy-pages#usage
2+
name: Deploy to GitHub Pages
3+
4+
on:
5+
workflow_dispatch:
6+
push:
7+
branches:
8+
- github-pages
9+
10+
jobs:
11+
build:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v3
15+
- run: corepack enable
16+
- uses: actions/setup-node@v3
17+
with:
18+
node-version: "18"
19+
20+
- run: pnpm install
21+
- run: BASE_URL="/solid-hackernews" pnpm run build
22+
env:
23+
NITRO_PRESET: github_pages
24+
25+
- name: Upload artifact
26+
uses: actions/upload-pages-artifact@v1
27+
with:
28+
path: ./.output/public
29+
30+
# Deployment job
31+
deploy:
32+
# Add a dependency to the build job
33+
needs: build
34+
35+
# Grant GITHUB_TOKEN the permissions required to make a Pages deployment
36+
permissions:
37+
pages: write # to deploy to Pages
38+
id-token: write # to verify the deployment originates from an appropriate source
39+
40+
# Deploy to the github_pages environment
41+
environment:
42+
name: github_pages
43+
url: ${{ steps.deployment.outputs.page_url }}
44+
45+
# Specify runner + deployment step
46+
runs-on: ubuntu-latest
47+
steps:
48+
- name: Deploy to GitHub Pages
49+
id: deployment
50+
uses: actions/deploy-pages@v1

app.config.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { defineConfig } from "@solidjs/start/config";
22

3+
const baseURL = process.env.BASE_URL || "";
4+
35
export default defineConfig({
6+
ssr: false,
47
server: {
5-
preset: "netlify",
8+
preset: "github_pages",
9+
baseURL,
610
},
711
});

src/app.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ import { Suspense } from "solid-js";
55
import "./app.css";
66
import Nav from "./components/nav";
77

8+
const base = import.meta.env.SERVER_BASE_URL;
9+
810
export default function App() {
911
return (
1012
<Router
13+
base={base}
1114
root={(props) => (
1215
<>
1316
<Nav />

src/components/comment.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { createSignal, For, Show } from "solid-js";
2+
import { A } from "@solidjs/router";
23
import type { CommentDefinition } from "../types";
34

45
const pluralize = (n: number) => n + (n === 1 ? " reply" : " replies");
@@ -9,7 +10,7 @@ export default function Comment(props: { comment: CommentDefinition }) {
910
return (
1011
<li class="comment">
1112
<div class="by">
12-
<a href={`/users/${props.comment.user}`}>{props.comment.user}</a>{" "}
13+
<A href={`/users/${props.comment.user}`}>{props.comment.user}</A>{" "}
1314
{props.comment.time_ago} ago
1415
</div>
1516
<div class="text" innerHTML={props.comment.content} />

src/components/nav.tsx

+14-12
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,32 @@
1+
import { A } from "@solidjs/router";
2+
13
export default function Nav() {
24
return (
35
<header class="header" $ServerOnly>
46
<nav class="inner">
5-
<a href="/">
7+
<A href="/">
68
<strong>HN</strong>
7-
</a>
8-
<a href="/new">
9+
</A>
10+
<A href="/new">
911
<strong>New</strong>
10-
</a>
11-
<a href="/show">
12+
</A>
13+
<A href="/show">
1214
<strong>Show</strong>
13-
</a>
14-
<a href="/ask">
15+
</A>
16+
<A href="/ask">
1517
<strong>Ask</strong>
16-
</a>
17-
<a href="/job">
18+
</A>
19+
<A href="/job">
1820
<strong>Jobs</strong>
19-
</a>
20-
<a
21+
</A>
22+
<A
2123
class="github"
2224
href="http://github.com/solidjs/solid"
2325
target="_blank"
2426
rel="noreferrer"
2527
>
2628
Built with Solid
27-
</a>
29+
</A>
2830
</nav>
2931
</header>
3032
);

src/routes/[...stories].tsx

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
createAsync,
3+
A,
34
type RouteDefinition,
45
cache,
56
type RouteSectionProps,
@@ -48,13 +49,13 @@ export default function Stories(props: RouteSectionProps) {
4849
</span>
4950
}
5051
>
51-
<a
52+
<A
5253
class="page-link"
5354
href={`/${type()}?page=${page() - 1}`}
5455
aria-label="Previous Page"
5556
>
5657
{"<"} prev
57-
</a>
58+
</A>
5859
</Show>
5960
<span>page {page()}</span>
6061
<Show
@@ -65,13 +66,13 @@ export default function Stories(props: RouteSectionProps) {
6566
</span>
6667
}
6768
>
68-
<a
69+
<A
6970
class="page-link"
7071
href={`/${type()}?page=${page() + 1}`}
7172
aria-label="Next Page"
7273
>
7374
more {">"}
74-
</a>
75+
</A>
7576
</Show>
7677
</div>
7778
<main class="news-list">

src/routes/stories/[id].tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
cache,
33
createAsync,
4+
A,
45
type RouteDefinition,
56
type RouteSectionProps,
67
} from "@solidjs/router";
@@ -25,15 +26,15 @@ export default function Story(props: RouteSectionProps) {
2526
<Show when={story()}>
2627
<div class="item-view">
2728
<div class="item-view-header">
28-
<a href={story()!.url} target="_blank">
29+
<A href={story()!.url} target="_blank">
2930
<h1>{story()!.title}</h1>
30-
</a>
31+
</A>
3132
<Show when={story()!.domain}>
3233
<span class="host">({story()!.domain})</span>
3334
</Show>
3435
<p class="meta">
3536
{story()!.points} points | by{" "}
36-
<a href={`/users/${story()!.user}`}>{story()!.user}</a>{" "}
37+
<A href={`/users/${story()!.user}`}>{story()!.user}</A>{" "}
3738
{story()!.time_ago} ago
3839
</p>
3940
</div>

0 commit comments

Comments
 (0)