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

feat: route support for Astro, Nuxt, Remix, Sveltekit and Vue #151

Merged
merged 3 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
.next/
dist/
.astro/
.vercel/
.nuxt/
.output/
.cache/
build/
.svelte-kit/
pnpm-lock.yaml
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>
</>
);
}
24 changes: 24 additions & 0 deletions apps/nuxt/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Nuxt dev/build outputs
.output
.data
.nuxt
.nitro
.cache
dist

# Node dependencies
node_modules

# Logs
logs
*.log

# Misc
.DS_Store
.fleet
.idea

# Local env files
.env
.env.*
!.env.example
29 changes: 29 additions & 0 deletions apps/nuxt/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Nuxt 3 Demo application for Vercel Speed-insights

## Setup

This application was created with the following commands:

- `cd apps`
- `pnpx nuxi@latest init nuxt` (answers: npm, no git)
- `cd nuxt`
- `rm -rf node_modules .nuxt`
- 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.
We also imported and used `<WebAnalytics />` component in `layouts/default.vue` file:

```vue
<script setup>
import { WebAnalytics } from '@vercel/analytics/vue';
</script>

<template>
<WebAnalytics />
</template>
```

## Usage

Start it with `pnpm -F nuxt dev` and browse to [http://localhost:3000](http://localhost:3000)
5 changes: 5 additions & 0 deletions apps/nuxt/app.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<template>
<NuxtLayout>
<NuxtPage />
</NuxtLayout>
</template>
Loading
Loading