Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[removed] #103

Merged
merged 28 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
88acfd2
fix: use [email protected] [Remove me from CHAGELOG.md]
brillout Aug 2, 2024
545eb8b
feat: new settings [`htmlAttributes`](https://vike.dev/htmlAttributes…
brillout Aug 2, 2024
964bb66
fix: fix type Config['title']
brillout Aug 2, 2024
8681dd3
fix: make title setting generate <meta property="og:title">
brillout Aug 2, 2024
06c5461
feat: new settings [`description`](https://vike.dev/description)
brillout Aug 2, 2024
d759f7e
fix: improve JSDocs
brillout Aug 2, 2024
0c25292
feat: new settings [`image`](https://vike.dev/image)
brillout Aug 2, 2024
e917040
fix: make favicon setting global
brillout Aug 2, 2024
1f91f16
fix: avoid the default of title/lang setting to override Head setting
brillout Aug 2, 2024
bb60ac2
feat: new setting `viewport`
brillout Aug 2, 2024
b27b3fe
remove outdated code
brillout Aug 2, 2024
149f555
feat: new hook [`onAfterRenderClient`](https://vike.dev/onAfterRender…
brillout Aug 2, 2024
af90fbc
minor refactor: align with vike-react
brillout Aug 2, 2024
f0dcf6e
minor refactor: align with vike-react
brillout Aug 2, 2024
682f5a6
determine head after body
brillout Aug 2, 2024
1f2122f
minor refactor
brillout Aug 2, 2024
66ca3e2
minor refactor
brillout Aug 4, 2024
d870795
add script
brillout Aug 4, 2024
c5dd9bd
fix: make Head setting cumulative
brillout Aug 4, 2024
d66c678
fix: export Vike config only at /config
brillout Aug 4, 2024
d46cab6
update link
brillout Aug 4, 2024
ab747da
fix: remove <ClientOnly> component
brillout Aug 5, 2024
81c6e40
minor refactor
brillout Aug 5, 2024
a028888
improve test
brillout Aug 6, 2024
88496ed
feat: [useConfig()](https://vike.dev/useConfig)
brillout Aug 4, 2024
d2d95bf
feat: new [components `<Head>` and `<Config>`](https://vike.dev/useCo…
brillout Aug 6, 2024
875db34
add example
brillout Aug 6, 2024
98e53b7
add test
brillout Aug 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 46 additions & 9 deletions examples/full/.testRun.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
export { testRun };

import { test, expect, run, fetchHtml, page, getServerUrl, autoRetry, partRegex } from "@brillout/test-e2e";
import assert from "node:assert";
const dataHk = partRegex`data-hk="${/[0-9-]+/}"`;

let isProd: boolean;

Expand All @@ -9,23 +11,24 @@ function testRun(cmd: `pnpm run ${"dev" | "preview"}`) {

isProd = cmd !== "pnpm run dev";

const title = "My Vike + Solid App";
testUrl({
url: "/",
title,
title: "My Vike + Solid App",
text: "Rendered to HTML.",
counter: true,
});

testUrl({
url: "/star-wars",
title: "6 Star Wars Movies",
description: "All the 6 movies from the Star Wars franchise",
text: "A New Hope",
});

testUrl({
url: "/star-wars/3",
title: "Return of the Jedi",
description: "Star Wars Movie Return of the Jedi from Richard Marquand",
text: "1983-05-25",
});

Expand All @@ -39,6 +42,8 @@ function testRun(cmd: `pnpm run ${"dev" | "preview"}`) {
});

testNavigationBetweenWithSSRAndWithoutSSR();

testHeadComponent();
}

function testNavigationBetweenWithSSRAndWithoutSSR() {
Expand Down Expand Up @@ -85,12 +90,14 @@ function testNavigationBetweenWithSSRAndWithoutSSR() {
function testUrl({
url,
title,
description,
text,
counter,
noSSR,
}: {
url: string;
title: string;
description?: string;
text: string;
counter?: true;
noSSR?: true;
Expand All @@ -100,15 +107,12 @@ function testUrl({
if (!noSSR) {
expect(html).toContain(text);
}

expect(getTitle(html)).toBe(title);
const hash = /[a-zA-Z0-9_-]+/;
const dataHkHash = /[0-9-]+/;
expect(html).toMatch(partRegex`<link ${dataHk} rel="icon" href="${getAssetUrl("logo.svg")}">`);

if (!isProd) {
expect(html).toMatch(partRegex`<link data-hk="${dataHkHash}" rel="icon" href="/assets/logo.svg">`);
} else {
expect(html).toMatch(partRegex`<link data-hk="${dataHkHash}" rel="icon" href="/assets/static/logo.${hash}.svg">`);
}
if (!description) description = "Demo showcasing Vike + Solid";
expect(html).toMatch(partRegex`<meta name="description" content="${description}">`);
});
test(url + " (Hydration)", async () => {
await page.goto(getServerUrl() + url);
Expand All @@ -120,6 +124,30 @@ function testUrl({
});
}

function testHeadComponent() {
test("Head Component (HTML)", async () => {
const html = await fetchHtml("/images");
expect(html).toMatch(
partRegex`<script ${dataHk} type="application/ld+json">{"@context":"https://schema.org/","contentUrl":{"src":"${getAssetUrl(
"logo-new.svg",
)}"},"creator":{"@type":"Person","name":"brillout"}}</script>`,
);
expect(html).toMatch(
partRegex`<script ${dataHk} type="application/ld+json">{"@context":"https://schema.org/","contentUrl":{"src":"${getAssetUrl(
"logo.svg",
)}"},"creator":{"@type":"Person","name":"Romuald Brillout"}}</script>`,
);
});
test("Head Component (Hydration)", async () => {
await page.goto(getServerUrl() + "/");
await testCounter();
ensureWasClientSideRouted("/pages/index");
await page.click('a:has-text("Head Component")');
await testCounter();
ensureWasClientSideRouted("/pages/index");
});
}

function getTitle(html: string) {
const title = html.match(/<title>(.*?)<\/title>/i)?.[1];
return title;
Expand Down Expand Up @@ -161,3 +189,12 @@ function findFirstPageId(html: string) {
expect(pageId).toBeTruthy();
return pageId;
}

function getAssetUrl(fileName: string) {
if (!isProd) {
return `/assets/${fileName}`;
}
const [fileBaseName, fileExt, ...r] = fileName.split(".");
assert(r.length === 0);
return partRegex`/assets/static/${fileBaseName}.${/[a-zA-Z0-9_-]+/}.${fileExt}`;
}
58 changes: 58 additions & 0 deletions examples/full/assets/logo-new.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion examples/full/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"dependencies": {
"node-fetch": "^3.3.2",
"solid-js": "^1.8.17",
"vike": "^0.4.181",
"vike": "^0.4.182",
"vike-solid": "link:vike-solid"
},
"devDependencies": {
Expand Down
1 change: 0 additions & 1 deletion examples/full/pages/+Head.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import logoUrl from "../assets/logo.svg";
export function Head() {
return (
<>
<meta name="description" content="Demo showcasing Vike + Solid" />
<link rel="icon" href={logoUrl} />
</>
);
Expand Down
1 change: 1 addition & 0 deletions examples/full/pages/+Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export function Layout(props: { children?: JSX.Element }) {
<Link href="/without-ssr">Without SSR</Link>
<Link href="/starship">Nested Layout 1</Link>
<Link href="/stardust">Nested Layout 2</Link>
<Link href="/images">Head Component</Link>
</Sidebar>
<Content>{props.children}</Content>
</div>
Expand Down
7 changes: 5 additions & 2 deletions examples/full/pages/+config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import type { Config } from "vike/types";

// Default config (can be overridden by pages)
export default {
// <title>
title: "My Vike + Solid App",
title: "My Vike + Solid App", // <title>
description: "Demo showcasing Vike + Solid", // <meta name="description">
bodyAttributes: {
class: "dark",
},
extends: vikeSolid,
} satisfies Config;
46 changes: 46 additions & 0 deletions examples/full/pages/images/+Page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
export { Page };

import { Head } from "vike-solid/Head";
import logoOld from "../../assets/logo.svg";
import logoNew from "../../assets/logo-new.svg";
import { Counter } from "../../components/Counter";

function Page() {
return (
<>
<p>
Page showcasing <code>{"<Image>"}</code> component, with structured data (see HTML).
</p>
<div>
New logo: <Image src={logoNew} author="brillout" />
</div>
<br />
<div>
Old logo: <Image src={logoOld} author="Romuald Brillout" />
</div>
<br />
<Counter />
</>
);
}

function Image({ src, author }: { src: string; author: string }) {
return (
<>
<img src={src} height={48} style={{ "vertical-align": "middle", "margin-left": "10px" }} />
<Head>
<script
type="application/ld+json"
innerHTML={JSON.stringify({
"@context": "https://schema.org/",
contentUrl: { src },
creator: {
"@type": "Person",
name: author,
},
})}
></script>
</Head>
</>
);
}
10 changes: 10 additions & 0 deletions examples/full/pages/star-wars/@id/+data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,25 @@ export { data };
export type Data = Awaited<ReturnType<typeof data>>;

import fetch from "node-fetch";
import { useConfig } from "vike-solid/useConfig";
import type { PageContextServer } from "vike/types";
import type { MovieDetails } from "../types.js";

const data = async (pageContext: PageContextServer) => {
const config = useConfig();

const response = await fetch(`https://brillout.github.io/star-wars/api/films/${pageContext.routeParams?.id}.json`);
let movie = (await response.json()) as MovieDetails;

config({
title: movie.title,
description: `Star Wars Movie ${movie.title} from ${movie.director}`,
});

// We remove data we don't need because we pass `pageContext.movie` to
// the client; we want to minimize what is sent over the network.
movie = minimize(movie);

return movie;
};

Expand Down
9 changes: 0 additions & 9 deletions examples/full/pages/star-wars/@id/+title.ts

This file was deleted.

9 changes: 9 additions & 0 deletions examples/full/pages/star-wars/index/+description.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export { description };

import type { Data } from "./+data.js";
import type { PageContext } from "vike/types";

function description(pageContext: PageContext<Data>) {
const movies = pageContext.data;
return `All the ${movies.length} movies from the Star Wars franchise`;
}
2 changes: 1 addition & 1 deletion examples/minimal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
},
"dependencies": {
"solid-js": "^1.8.17",
"vike": "^0.4.181",
"vike": "^0.4.182",
"vike-solid": "link:vike-solid"
},
"devDependencies": {
Expand Down
20 changes: 10 additions & 10 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading