the alias

This commit is contained in:
2025-09-05 14:39:43 -04:00
parent d761d6bde5
commit 0c7f7ff1ff
10 changed files with 78 additions and 66 deletions

View File

@@ -1,38 +1,3 @@
# sv
Everything you need to build a Svelte project, powered by [`sv`](https://github.com/sveltejs/cli).
## Creating a project
If you're seeing this, you've probably already done this step. Congrats!
```sh
# create a new project in the current directory
npx sv create
# create a new project in my-app
npx sv create my-app
```
## Developing
Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
```sh
npm run dev
# or start the server and open the app in a new browser tab
npm run dev -- --open
```
## Building
To create a production version of your app:
```sh
npm run build
```
You can preview the production build with `npm run preview`.
> To deploy your app, you may need to install an [adapter](https://svelte.dev/docs/kit/adapters) for your target environment.
This is a tutorial project being used for me to learn svelte. Following the official documentation at [svelte.dev](https://svelte.dev/tutorial/kit/introducing-sveltekit)

1
src/lib/message.js Normal file
View File

@@ -0,0 +1 @@
export const message = 'hello from $lib/messgae';

View File

@@ -0,0 +1,9 @@
export function load({ cookies }) {
const visited = cookies.get('visited');
cookies.set('visited', 'true', { path: '/' });
return {
visited: visited === 'true'
}
}

View File

@@ -1,2 +1,6 @@
<h1>Welcome to SvelteKit</h1>
<script>
let { data } = $props();
</script>
<h1>Welcome to SvelteKit, {data.visited ? 'friend' : 'stranger'}</h1>
<p>Visit <a href="https://svelte.dev/docs/kit">svelte.dev/docs/kit</a> to read the documentation</p>

View File

@@ -0,0 +1,10 @@
import { posts } from './data.js';
export function load() {
return {
summaries: posts.map((post) => ({
slug: post.slug,
title: post.title
}))
};
}

View File

@@ -1,10 +0,0 @@
import { posts } from './data';
export function load() {
return {
summaries: posts.map((post) => ({
slug: post.slug,
title: post.title
}))
}
}

View File

@@ -1,11 +1,14 @@
<script lang='ts'>
let { data } = $props();
<script>
let { data } = $props();
import { message } from '$lib/message.js'
</script>
<h1>Blog</h1>
<h1>blog</h1>
<ul>
{#each data.summaries as { slug, title }}
<li><a href="/blog/{slug}">{title}</a></li>
{/each}
</ul>
<ul class="list-disc list-inside">
{#each data.summaries as { slug, title }}
<li><a href="/blog/{slug}">{title}</a></li>
{/each}
</ul>
<p class="text-sm text-gray-400 italic">{message}</p>

View File

@@ -0,0 +1,30 @@
<script>
let { data, children } = $props();
</script>
<div class="layout">
<main>
{@render children()}
</main>
<aside>
<h2>More posts</h2>
<ul>
{#each data.summaries as { slug, title }}
<li>
<a href="/blog/{slug}">{title}</a>
</li>
{/each}
</ul>
</aside>
</div>
<style>
@media (min-width: 640px) {
.layout {
display: grid;
gap: 2em;
grid-template-columns: 1fr 16em;
}
}
</style>

View File

@@ -1,12 +1,12 @@
import { error } from '@sveltejs/kit';
import { posts } from '../data';
import { posts } from '../data.js';
export function load({ params }) {
const post = posts.find((post) => post.slug === params.slug);
const post = posts.find((post) => post.slug === params.slug);
if (!post) error(404)
if (!post) error(404);
return {
post
}
}
return {
post
};
}

View File

@@ -1,6 +1,6 @@
<script lang="ts">
let { data } = $props();
<script>
let { data } = $props();
</script>
<h1 class="text-2xl font-bold">{data.post.title}</h1>
<div>{@html data.post.content}</div>
<h1>{data.post.title}</h1>
<div>{@html data.post.content}</div>