Skip to content

Commit

Permalink
Capacity on main route
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael-Liendo committed Jan 18, 2024
1 parent ca9a4fa commit 83a3d4f
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 14 deletions.
12 changes: 1 addition & 11 deletions src/hooks.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,8 @@ export const handle: Handle = async ({ event, resolve }) => {
// read language slug
const [, lang] = event.url.pathname.split('/');

// redirect to base locale if no locale slug was found
if (!lang) {
const locale = getPreferredLocale(event);

return new Response(null, {
status: 302,
headers: { Location: `/${locale}` },
});
}

// if slug is not a locale, use base locale (e.g. api endpoints)
const locale = isLocale(lang) ? (lang as Locales) : getPreferredLocale(event);
const locale = isLocale(lang) ? (lang as Locales) : 'es';
const LL = L[locale];

// bind locale and translation functions to current request
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Note } from '$lib/utils/Notion/Notes/types.js';

/** @type {import('./$types').PageLoad} */
export async function load({ params, fetch }) {
const res = await fetch(`/api/notes/${params.lang}`);
const res = await fetch(`/api/notes/${params.lang ?? 'es'}`);

if (res.ok) {
const notes = await res.json();
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Note } from '$lib/utils/Notion/Notes/types.js';

/** @type {import('./$types').PageLoad} */
export async function load({ params, fetch }) {
const res = await fetch(`/api/notes/${params.lang}`);
const res = await fetch(`/api/notes/${params.lang ?? 'es'}`);

if (res.ok) {
const notes = await res.json();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import { error } from '@sveltejs/kit';
/** @type {import('./$types').PageLoad} */
export async function load({ params, fetch }) {
try {
const request = await fetch(`/api/note/${params.lang}/${params.slug}`);
const request = await fetch(
`/api/note/${params.lang ?? 'es'}/${params.slug}`,
);
const note = await request.json();

if (!note.note) {
Expand Down
73 changes: 73 additions & 0 deletions src/routes/[[lang=lang]]/projects/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<script lang="ts">
import { locale } from '$i18n/i18n-svelte';
import Entry from '$lib/components/Entry.svelte';
export let data: {
projects: any[];
};
let title = 'Projects | Michael Liendo';
let description =
'projects taken while reading about computer science and software development.';
let keywords =
'projects, blog, articles, writing, content, topics, tips, insights, experiences, knowledge';
let avatarUrl = 'https://avatars.githubusercontent.com/u/70660410?v=4';
$: {
switch ($locale) {
case 'en':
title = 'Projects | Michael Liendo';
description =
'projects taken while reading about computer science and software development.';
keywords =
'projects, blog, articles, writing, content, topics, tips, insights, experiences, knowledge';
break;
case 'es':
title = 'Proyectos | Michael Liendo';
description =
'Notas tomadas mientras leo sobre ciencias de la computación y desarrollo de software.';
keywords =
'notas, blog, artículos, escritura, contenido, temas, consejos, perspectivas, experiencias, conocimiento';
break;
}
}
</script>

<svelte:head>
<title>{title}</title>
<meta name="description" content={description} />
<meta name="keywords" content={keywords} />
<!-- Schema.org markup for Google+ -->
<meta itemprop="name" content={title} />
<meta itemprop="description" content={description} />
<meta itemprop="image" content={avatarUrl} />
<!-- Open Graph data -->
<meta property="og:title" content={title} />
<meta property="og:type" content="article" />
<meta property="og:url" content="https://michaelliendo.com/" />
<meta property="og:image" content={avatarUrl} />
<meta property="og:description" content={description} />
<meta property="og:site_name" content="Michael Liendo" />
<!-- Twitter Card data -->
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:site" content="@MichaelMLiendo" />
<meta name="twitter:title" content={title} />
<meta name="twitter:description" content={description} />
<meta name="twitter:creator" content="@MichaelMLiendo" />
<meta name="twitter:image:src" content={avatarUrl} />
</svelte:head>

<ul
class="max-w-5xl m-auto flex flex-col md:grid md:grid-cols-3 md:gap-6 px-4 md:px-0"
>
{#each data.projects as project}
<Entry
title={project.title}
description={project.description}
publishDate={new Date(project.date)}
tags={project.tags}
slug={project.slug}
previewImageUrl={project.cover}
/>
{/each}
</ul>
16 changes: 16 additions & 0 deletions src/routes/[[lang=lang]]/projects/+page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/** @type {import('./$types').PageLoad} */
export async function load({ fetch }) {
const res = await fetch('/api/projects');

if (res.ok) {
const projects = await res.json();

return {
projects: projects as unknown[],
};
}

return {
projects: [],
};
}
8 changes: 8 additions & 0 deletions src/routes/api/projects/+server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { getProjects } from '$lib/utils/Notion/Notes';

/** @type {import('./$types').RequestHandler} */
export async function GET() {
const projects = await getProjects();

return new Response(JSON.stringify(projects), { status: 200 });
}

0 comments on commit 83a3d4f

Please sign in to comment.