Skip to content

Commit afdc3ce

Browse files
authored
Fix search and warnings (#18)
* fix image warning * fix "Hydration failed/mismatch" * fix search
1 parent 2211a38 commit afdc3ce

6 files changed

Lines changed: 42 additions & 63 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -23,58 +23,40 @@ jobs:
2323
- name: Checkout
2424
uses: actions/checkout@v5
2525

26-
- name: Detect package manager
27-
id: detect-package-manager
28-
run: |
29-
if [ -f "./yarn.lock" ]; then
30-
echo "manager=yarn" >> $GITHUB_OUTPUT
31-
echo "command=install" >> $GITHUB_OUTPUT
32-
echo "runner=yarn" >> $GITHUB_OUTPUT
33-
exit 0
34-
elif [ -f "./package.json" ]; then
35-
echo "manager=npm" >> $GITHUB_OUTPUT
36-
echo "command=ci" >> $GITHUB_OUTPUT
37-
echo "runner=npx --no-install" >> $GITHUB_OUTPUT
38-
exit 0
39-
else
40-
echo "Unable to determine package manager"
41-
exit 1
42-
fi
43-
4426
- name: Setup Node
4527
uses: actions/setup-node@v5
4628
with:
47-
node-version: "26"
29+
node-version: "22"
30+
cache: npm
4831

4932
- name: Setup Pages
5033
uses: actions/configure-pages@v6
5134

52-
- name: Restore cache
35+
- name: Restore Next.js cache
5336
uses: actions/cache@v5
5437
with:
5538
path: |
5639
.next/cache
57-
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }}
40+
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }}
5841
restore-keys: |
59-
${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-
42+
${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-
6043
6144
- name: Install dependencies
62-
run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }}
63-
working-directory: .
45+
run: npm ci
6446

65-
- name: Build with Next.js
66-
run: ${{ steps.detect-package-manager.outputs.runner }} next build
67-
working-directory: .
47+
# Must use `npm run build` (not `npx next build`) so the postbuild
48+
# Pagefind step runs and writes search assets into out/_pagefind.
49+
- name: Build static site
50+
run: npm run build
6851

69-
- name: Copy built files to docs
70-
run: |
71-
rm -rf docs/*
72-
cp -r ./out docs/
52+
- name: Verify Pagefind index
53+
run: test -f out/_pagefind/pagefind.js
7354

7455
- name: Upload artifact
7556
uses: actions/upload-pages-artifact@v5
7657
with:
77-
path: docs
58+
path: out
59+
7860
deploy:
7961
environment:
8062
name: github-pages

README.md

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,16 @@ bun dev
1616

1717
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
1818

19-
You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
19+
**Enable Search on Dev**
2020

21-
This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel.
21+
To enable/test search functionality on development server, run the following command:
2222

23-
## Learn More
24-
25-
To learn more about Next.js, take a look at the following resources:
26-
27-
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
28-
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
29-
30-
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome!
31-
32-
## Deploy on Vercel
23+
```bash
24+
npm run build
25+
```
3326

34-
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
27+
and then
3528

36-
Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details.
29+
```bash
30+
npm run start
31+
```

components/FooterLogo.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ export function FooterLogo() {
99
<Image
1010
src="/logo-UoN-light.png"
1111
alt="University of Nottingham"
12-
width={200}
13-
height={200}
14-
className="block dark:hidden"
12+
width={100}
13+
height={100}
14+
className="block dark:hidden w-[200px] h-auto"
1515
/>
1616

1717
<Image
1818
src="/logo-UoN-dark.png"
1919
alt="University of Nottingham"
20-
width={200}
21-
height={200}
22-
className="hidden dark:block"
20+
width={100}
21+
height={100}
22+
className="hidden dark:block w-[200px] h-auto"
2323
/>
2424
</>
2525
);

components/doc-metadata/TimeToRead.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { LucideClock } from "lucide-react";
22
import { FrontMatter } from "nextra";
3-
import { useEffect } from "react";
3+
import { useEffect, useState } from "react";
44

55
// conditionally polyfill Temporal for Safari :(
66
const loadTemporal = async () => {
@@ -13,9 +13,16 @@ const loadTemporal = async () => {
1313
await loadTemporal();
1414

1515
export function TimeToRead({ metadata }: { metadata?: FrontMatter }) {
16-
if (metadata?.readingTime == null) return null;
16+
const [text, setText] = useState<string | null>(null);
1717

18-
useEffect(() => { loadTemporal() }, [])
18+
useEffect(() => {
19+
loadTemporal().then(() => {
20+
if (metadata?.readingTime == null) return;
21+
setText(Temporal.Duration.from(metadata.readingTime).toLocaleString());
22+
});
23+
}, [metadata]);
24+
25+
if (!text) return null; // or a static fallback
1926

2027
return (<dl className="flex w-full p-2 gap-2 items-center">
2128
<dt className="">
@@ -24,7 +31,7 @@ export function TimeToRead({ metadata }: { metadata?: FrontMatter }) {
2431
</div>
2532
</dt>
2633
<dd>
27-
{Temporal.Duration.from(metadata.readingTime).toLocaleString()}
34+
{text}
2835
</dd>
2936
</dl>)
3037
}

next.config.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,13 @@ const nextConfig: NextConfig = {
66
images: {
77
unoptimized: true,
88
},
9-
distDir: "out",
109
output: "export",
1110
basePath: "",
1211
assetPrefix: "",
1312
};
1413

15-
// Set up Nextra with its configuration
16-
const withNextra = nextra({
17-
search: false,
18-
});
14+
const withNextra = nextra({});
1915

20-
// Export the final Next.js config with Nextra included
2116
export default withNextra({
2217
...nextConfig,
2318
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"scripts": {
66
"dev": "next --turbopack",
77
"build": "next build",
8-
"start": "next start",
8+
"start": "npx serve out",
99
"lint": "eslint",
1010
"postbuild": "pagefind --site .next/server/app --output-path out/_pagefind"
1111
},

0 commit comments

Comments
 (0)