Skip to content

Commit

Permalink
feat: adds route support for remix and astro, fixes others
Browse files Browse the repository at this point in the history
  • Loading branch information
feugy committed Nov 6, 2024
1 parent bb04523 commit 8c9cf45
Show file tree
Hide file tree
Showing 54 changed files with 4,550 additions and 4,918 deletions.
24 changes: 24 additions & 0 deletions apps/astro/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# build output
dist/
# generated types
.astro/

# dependencies
node_modules/

# logs
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*


# environment variables
.env
.env.production

# macOS-specific files
.DS_Store

# jetbrains setting folder
.idea/
37 changes: 37 additions & 0 deletions apps/astro/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Astro Demo application for Vercel Speed-insights

## Setup

This application was created with the following commands:

- `cd apps`
- `pnpm create astro@latest astro` (answers: empty, no to all)
- `cd astro`
- manually edit package.json to add `"@vercel/analytics": "workspace:*"` dependency
- `pnpm i`

Then we've added:

1. a simple collection of Markdown blog posts in `src/contents/blog` folder
2. a blog post page in `src/pages/blog/[...slug].astro`
3. an index page in `src/pages/index.astro` which list all available blog posts
4. a layout in `src/components/Base.astro`, used in both page, which includes our Analytics.astro component:

```astro
---
import Analytics from '@vercel/analytics/astro';
---
<html lang="en">
<head>
<!-- ...-->
<Analytics />
</head>
<body>
<slot />
</body>
</html>
```

## Usage

Start it with `pnpm -F nuxt dev` and browse to [http://localhost:4321](http://localhost:4321)
4 changes: 4 additions & 0 deletions apps/astro/astro.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { defineConfig } from 'astro/config';

// https://astro.build/config
export default defineConfig({});
22 changes: 22 additions & 0 deletions apps/astro/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "astro",
"version": "0.0.1",
"private": true,
"type": "module",
"scripts": {
"astro": "astro",
"build": "astro build",
"dev": "astro dev",
"preview": "astro preview",
"start": "astro dev"
},
"dependencies": {
"@vercel/analytics": "workspace:*",
"astro": "latest"
},
"devDependencies": {
"@astrojs/check": "^0.5.4",
"@vercel/analytics": "workspace:*",
"typescript": "^5.3.3"
}
}
9 changes: 9 additions & 0 deletions apps/astro/public/favicon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions apps/astro/src/components/BaseHead.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
import Analytics from '@vercel/analytics/astro';
---
<Analytics />
6 changes: 6 additions & 0 deletions apps/astro/src/content/blog/bruno.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
title: About Bruno
slug: bruno
---

We don't talk about Bruno
6 changes: 6 additions & 0 deletions apps/astro/src/content/blog/henry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
title: About Henry
slug: henry
---

Henry is a gentleman
1 change: 1 addition & 0 deletions apps/astro/src/env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference path="../.astro/types.d.ts" />
18 changes: 18 additions & 0 deletions apps/astro/src/layouts/Base.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
import Analytics from '@vercel/analytics/astro';
const { title } = Astro.props;
---
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<meta name="viewport" content="width=device-width" />
<meta name="generator" content={Astro.generator} />
<title>{title}</title>
<Analytics />
</head>
<body>
<slot />
</body>
</html>
18 changes: 18 additions & 0 deletions apps/astro/src/pages/blog/[...slug].astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
import { getCollection } from 'astro:content';
import Layout from '../../layouts/Base.astro';
export async function getStaticPaths() {
const blogEntries = await getCollection('blog');
return blogEntries.map(entry => ({
params: { slug: entry.slug }, props: { entry },
}));
}
const { entry } = Astro.props;
const { Content } = await entry.render();
---
<Layout title={entry.data.title}>
<Content />
<p><a href="/">back</a></p>
</Layout>
16 changes: 16 additions & 0 deletions apps/astro/src/pages/index.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
import { getCollection } from 'astro:content';
import Layout from '../layouts/Base.astro';
const blogEntries = await getCollection('blog');
---
<Layout title="Astro">
<h1>Welcome to Astro</h1>
<ul>
{blogEntries.map(blogPostEntry => (
<li>
<a href={`/blog/${blogPostEntry.slug}`}>{blogPostEntry.data.title}</a>
</li>
))}
</ul>
</Layout>
6 changes: 6 additions & 0 deletions apps/astro/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "astro/tsconfigs/base",
"compilerOptions": {
"strictNullChecks": true
}
}
16 changes: 16 additions & 0 deletions apps/nextjs-15/src/app/blog/[slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import Link from 'next/link';

export default async function BlogPage({
params,
}: {
params: Promise<{ slug: string }>;
}) {
const { slug } = await params;
return (
<div>
<h2>{slug}</h2>

<Link href="/blog">Back to blog</Link>
</div>
);
}
12 changes: 12 additions & 0 deletions apps/nextjs-15/src/app/blog/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Link from 'next/link';

export default function Layout({ children }: { children: React.ReactNode }) {
return (
<div>
<Link href="/blog/my-first-blogpost">My first blog post</Link>&nbsp;
<Link href="/blog/new-feature-release">Feature just got released</Link>
<br />
<div>{children}</div>
</div>
);
}
3 changes: 3 additions & 0 deletions apps/nextjs-15/src/app/blog/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Blog() {
return <div>Welcome to the blog</div>;
}
3 changes: 2 additions & 1 deletion apps/nextjs/app/blog/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import Link from 'next/link';
export default function Layout({ children }: { children: React.ReactNode }) {
return (
<div>
<Link href="/blog/my-first-blogpost">My first blog post</Link>
<Link href="/blog/my-first-blogpost">My first blog post</Link>&nbsp;{' '}
<Link href="/blog/new-feature-release">Feature just got released</Link>
<br />
<div>{children}</div>
</div>
);
Expand Down
2 changes: 1 addition & 1 deletion apps/nextjs/app/blog/page.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export default function Blog() {
return <div>Welcome on the blog</div>;
return <div>Welcome to the app-router blog</div>;
}
7 changes: 7 additions & 0 deletions apps/nextjs/pages/blog-pages/[slug].tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function BlogPage() {
return (
<div>
<h1>Blog Page</h1>
</div>
);
}
19 changes: 18 additions & 1 deletion apps/nextjs/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
import Link from 'next/link';

export default function Page() {
return null;
return (
<>
<div>Testing web analytics</div>
<ul>
<li>
<Link href="/blog-pages/page-a">Pages directory A</Link>
</li>
<li>
<Link href="/blog-pages/page-b">Pages directory B</Link>
</li>
<li>
<Link href="/blog">App directory</Link>
</li>
</ul>
</>
);
}
2 changes: 1 addition & 1 deletion apps/nuxt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This application was created with the following commands:
- `pnpx nuxi@latest init nuxt` (answers: npm, no git)
- `cd nuxt`
- `rm -rf node_modules .nuxt`
- manually edit package.json to add `"@vercel/speed-insights": "workspace:*"` dependency
- manually edit package.json to add `"@vercel/analytics": "workspace:*"` dependency
- `pnpm i`

Then we moved some code from vue's official template (styles, HelloWorld SFC) and added a few dynamic route to illustrate the use.
Expand Down
4 changes: 2 additions & 2 deletions apps/nuxt/layouts/default.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { WebAnalytics } from '@vercel/analytics/nuxt';
import { Analytics } from '@vercel/analytics/nuxt';
import { track } from '@vercel/analytics';
function navigate(event) {
Expand All @@ -8,7 +8,7 @@ function navigate(event) {
</script>

<template>
<WebAnalytics />
<Analytics />
<header>
<img
alt="Vue logo"
Expand Down
4 changes: 4 additions & 0 deletions apps/remix/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/** @type {import('eslint').Linter.Config} */
module.exports = {
extends: ['@remix-run/eslint-config', '@remix-run/eslint-config/node'],
};
2 changes: 1 addition & 1 deletion apps/remix/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ node_modules
/build
/public/build
.env

.cache
12 changes: 10 additions & 2 deletions apps/remix/app/root.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
import { cssBundleHref } from '@remix-run/css-bundle';
import type { LinksFunction } from '@remix-run/node';
import {
Links,
LiveReload,
Meta,
Outlet,
Scripts,
ScrollRestoration,
} from "@remix-run/react";
import { Analytics } from "@vercel/analytics/react";
} from '@remix-run/react';
import { Analytics } from '@vercel/analytics/remix';

export const links: LinksFunction = () => [
...(cssBundleHref ? [{ rel: 'stylesheet', href: cssBundleHref }] : []),
];

export default function App() {
return (
<html lang="en">
<head>
<meta charSet="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<Meta />
<Links />
</head>
Expand Down
11 changes: 7 additions & 4 deletions apps/remix/app/routes/_index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { json } from "@vercel/remix";
import { Form, useActionData } from "@remix-run/react";
import { track } from "@vercel/analytics/server";
import { json } from '@vercel/remix';
import { Form, Link, useActionData } from '@remix-run/react';
import { track } from '@vercel/analytics/server';

export const action = async () => {
await track("Server Action", { some: "data" });
await track('Server Action', { some: 'data' });
return json({ success: true });
};

Expand All @@ -19,6 +19,9 @@ export default function Home() {
<button type="submit">Submit action</button>
</Form>
)}
<Link to="/blog/henri">About Henri</Link>
<br />
<Link to="/blog/bruno">About Bruno</Link>
</main>
);
}
19 changes: 19 additions & 0 deletions apps/remix/app/routes/blog.$slug.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { json, type LoaderFunctionArgs } from '@remix-run/node';
import { Link, useLoaderData } from '@remix-run/react';
import { track } from '@vercel/analytics';

export const loader = async ({ params }: LoaderFunctionArgs) => {
return json({ slug: params.slug });
};

export default function BlogPage() {
const { slug } = useLoaderData<typeof loader>();
return (
<div>
<h1>Blog</h1>
<p>We don't talk about {slug}</p>
<br />
<Link to="/">Back</Link>
</div>
);
}
Loading

0 comments on commit 8c9cf45

Please sign in to comment.