Skip to content

Commit

Permalink
feat(web): switch from Next.js to Astro
Browse files Browse the repository at this point in the history
  • Loading branch information
mheob committed Aug 26, 2024
1 parent a1827f3 commit 5f59d10
Show file tree
Hide file tree
Showing 40 changed files with 3,113 additions and 1,278 deletions.
3 changes: 3 additions & 0 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
],
"words": [
"Aufzählungspunkte",
"astro",
"Blogautor",
"Blogpost",
"Blogposts",
"Codespaces",
"commitlint",
"dotenv",
"evenodd",
Expand All @@ -36,6 +38,7 @@
"opengraph",
"Porträtbild",
"pragent",
"Preact",
"Shitposting",
"sonarcloud",
"vercel",
Expand Down
13 changes: 8 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# Jetbrains setting folder
.idea/

# Dependencies
node_modules
.pnp
Expand All @@ -8,21 +11,21 @@ node_modules
# Local env files
.env
.env.local
.env.development
.env.development.local
.env.test.local
.env.production
.env.production.local
.env.test
.env.test.local

# Testing
coverage

# Turbo
.turbo

# Vercel
.turbo
.vercel

# Build Outputs
.next/
out/
build
dist
Expand Down
Empty file removed .npmrc
Empty file.
4 changes: 4 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"recommendations": ["astro-build.astro-vscode"],
"unwantedRecommendations": []
}
11 changes: 11 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"version": "0.2.0",
"configurations": [
{
"command": "./apps/web/node_modules/.bin/astro dev",
"name": "Astro - Development server",
"request": "launch",
"type": "node-terminal"
}
]
}
2 changes: 2 additions & 0 deletions apps/studio/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@

# Dotenv and similar local-only files
*.local
.vercel
.env*.local
2 changes: 1 addition & 1 deletion apps/studio/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ export const projectId = assertValue(
/**
* see https://www.sanity.io/docs/api-versioning for how versioning works
*/
export const apiVersion = process.env.SANITY_API_VERSION || '2022-03-07';
export const apiVersion = process.env.SANITY_API_VERSION ?? '2022-03-07';
22 changes: 11 additions & 11 deletions apps/studio/plugins/singleton.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type DocumentDefinition, definePlugin } from 'sanity';
import { definePlugin, type DocumentDefinition } from 'sanity';
import type { StructureResolver } from 'sanity/structure';

import { getGroup, isExcludedDefaultListItem } from '@/structure';
Expand All @@ -11,18 +11,18 @@ export const singletonPlugin = definePlugin((types: string[]) => {
document: {
// Hide 'Singletons (such as Settings)' from new document options
// Removes the "duplicate" action on the Singletons (such as Home)
actions: (prev, { schemaType }) => {
actions: (previous, { schemaType }) => {
if (types.includes(schemaType)) {
return prev.filter(({ action }) => action !== 'duplicate');
return previous.filter(({ action }) => action !== 'duplicate');
}
return prev;
return previous;
},
// https://user-images.githubusercontent.com/81981/195728798-e0c6cf7e-d442-4e58-af3a-8cd99d7fcc28.png
newDocumentOptions: (prev, { creationContext }) => {
newDocumentOptions: (previous, { creationContext }) => {
if (creationContext.type === 'global') {
return prev.filter(templateItem => !types.includes(templateItem.templateId));
return previous.filter(templateItem => !types.includes(templateItem.templateId));
}
return prev;
return previous;
},
},
name: 'singletonPlugin',
Expand All @@ -33,23 +33,23 @@ export const singletonPlugin = definePlugin((types: string[]) => {
* The StructureResolver is how we're changing the DeskTool structure to linking to document
* (named Singleton) like how "Home" is handled.
*
* @param typeDefArray The array of document definitions that are singletons
* @param typeDefinitionArray The array of document definitions that are singletons
* @returns The StructureResolver
*/
export function pageStructure(typeDefArray: DocumentDefinition[]): StructureResolver {
export function pageStructure(typeDefinitionArray: DocumentDefinition[]): StructureResolver {
return S => {
// The default root list items (except custom ones)
const defaultListItems = S.documentTypeListItems().filter(
listItem =>
!typeDefArray.find(singleton => singleton.name === listItem.getId()) &&
!typeDefinitionArray.some(singleton => singleton.name === listItem.getId()) &&
isExcludedDefaultListItem(listItem.getId()),
);

return S.list()
.title('Base')
.items([
...getGroup(S, 'default'),
...getGroup(S, 'singletons', typeDefArray),
...getGroup(S, 'singletons', typeDefinitionArray),
S.divider(),
...getGroup(S, 'persons'),
...defaultListItems,
Expand Down
11 changes: 1 addition & 10 deletions apps/studio/sanity.cli.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable node/prefer-global/process */
/* eslint-disable node/prefer-global/process, unicorn/prefer-module */

import { defineCliConfig } from 'sanity/cli';

Expand All @@ -19,12 +19,3 @@ export default defineCliConfig({
},
},
});

// import { defineCliConfig } from 'sanity/cli';

// export default defineCliConfig({
// api: {
// dataset: process.env.SANITY_STUDIO_DATASET,
// projectId: process.env.SANITY_STUDIO_PROJECT_ID,
// },
// });
2 changes: 1 addition & 1 deletion apps/studio/schemas/singletons/site-settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const siteSettings = defineType({
group: 'meta',
description: (
<a
href="https://nextjs.org/docs/app/api-reference/functions/generate-metadata#metadatabase"
href="https://docs.astro.build/en/reference/api-reference/#astrourl"
rel="noreferrer noopener"
target="_blank"
>
Expand Down
2 changes: 2 additions & 0 deletions apps/studio/shared/validation-rules.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable unicorn/no-object-as-default-parameter */

import type { StringRule } from 'sanity';

interface RuleOptions {
Expand Down
39 changes: 23 additions & 16 deletions apps/studio/structure/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,24 @@ export function isExcludedSingletonListItem(id?: string) {
export function getGroup(
S: StructureBuilder,
name: DocumentGroup,
typeDefArray?: DocumentDefinition[],
typeDefinitionArray?: DocumentDefinition[],
): ListItemBuilder[] {
switch (name) {
case 'default':
case 'default': {
return getGroupNews(S);
case 'persons':
}
case 'persons': {
return getGroupPersons(S);
case 'settings':
}
case 'settings': {
return getGroupSettings(S);
case 'singletons':
return getGroupSingletons(S, typeDefArray);
default:
}
case 'singletons': {
return getGroupSingletons(S, typeDefinitionArray);
}
default: {
return getGroupSettings(S);
}
}
}

Expand Down Expand Up @@ -79,9 +84,9 @@ function getGroupSettings(S: StructureBuilder): ListItemBuilder[] {

function getGroupSingletons(
S: StructureBuilder,
typeDefArray?: DocumentDefinition[],
typeDefinitionArray?: DocumentDefinition[],
): ListItemBuilder[] {
if (!typeDefArray) return [];
if (!typeDefinitionArray) return [];
return [
S.listItem()
.title('Einzelseiten')
Expand All @@ -91,15 +96,17 @@ function getGroupSingletons(
S.list()
.title('Einzelseiten')
.items(
typeDefArray
.map(typeDef => {
typeDefinitionArray
.map(typeDefinition => {
return S.listItem()
.title(typeDef.title || typeDef.name)
.id(typeDef.name)
.icon(typeDef.icon)
.child(S.document().schemaType(typeDef.name).documentId(typeDef.name));
.title(typeDefinition.title ?? typeDefinition.name)
.id(typeDefinition.name)
.icon(typeDefinition.icon)
.child(
S.document().schemaType(typeDefinition.name).documentId(typeDefinition.name),
);
})
.filter(typeDef => isExcludedSingletonListItem(typeDef.getId())),
.filter(typeDefinition => isExcludedSingletonListItem(typeDefinition.getId())),
),
),
];
Expand Down
40 changes: 11 additions & 29 deletions apps/web/.gitignore
Original file line number Diff line number Diff line change
@@ -1,36 +1,18 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# build output
dist/

# dependencies
/node_modules
/.pnp
.pnp.js
.yarn/install-state.gz

# testing
/coverage

# next.js
/.next/
/out/

# production
/build
# generated types
.astro/

# misc
.DS_Store
*.pem
# dependencies
node_modules/

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

# env files (can opt-in for commiting if needed)
.env*

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts
# environment variables
.env
.env.production
63 changes: 33 additions & 30 deletions apps/web/README.md
Original file line number Diff line number Diff line change
@@ -1,44 +1,47 @@
# TODO README
# Astro Starter Kit: Minimal

This is a [Next.js](https://nextjs.org) project bootstrapped with
[`create-next-app`](https://nextjs.org/docs/app/api-reference/create-next-app).
```sh
npm create astro@latest -- --template minimal
```

## Getting Started
[![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/withastro/astro/tree/latest/examples/minimal)
[![Open with CodeSandbox](https://assets.codesandbox.io/github/button-edit-lime.svg)](https://codesandbox.io/p/sandbox/github/withastro/astro/tree/latest/examples/minimal)
[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/withastro/astro?devcontainer_path=.devcontainer/minimal/devcontainer.json)

First, run the development server:
> 🧑‍🚀 **Seasoned astronaut?** Delete this file. Have fun!
```bash
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev
```
## 🚀 Project Structure

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
Inside of your Astro project, you'll see the following folders and files:

You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
```text
/
├── public/
├── src/
│ └── pages/
│ └── index.astro
└── package.json
```

This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize
and load Inter, a custom Google Font.
Astro looks for `.astro` or `.md` files in the `src/pages/` directory. Each page is exposed as a route based on its file name.

## Learn More
There's nothing special about `src/components/`, but that's where we like to put any Astro/React/Vue/Svelte/Preact components.

To learn more about Next.js, take a look at the following resources:
Any static assets, like images, can be placed in the `public/` directory.

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
## 🧞 Commands

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are
welcome!
All commands are run from the root of the project, from a terminal:

## Deploy on Vercel
| Command | Action |
| :------------------------ | :----------------------------------------------- |
| `npm install` | Installs dependencies |
| `npm run dev` | Starts local dev server at `localhost:4321` |
| `npm run build` | Build your production site to `./dist/` |
| `npm run preview` | Preview your build locally, before deploying |
| `npm run astro ...` | Run CLI commands like `astro add`, `astro check` |
| `npm run astro -- --help` | Get help using the Astro CLI |

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.
## 👀 Want to learn more?

Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more
details.
Feel free to check [our documentation](https://docs.astro.build) or jump into our [Discord server](https://astro.build/chat).
4 changes: 4 additions & 0 deletions apps/web/astro.config.ts
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({});
8 changes: 0 additions & 8 deletions apps/web/next.config.mjs

This file was deleted.

Loading

0 comments on commit 5f59d10

Please sign in to comment.