clean blog urls
|
@ -6,7 +6,7 @@
|
|||
const postHtml = `${post.html}<sty` + `le>${post.css}</style>`
|
||||
</script>
|
||||
|
||||
<a href="/blog/{post.slug}" class="preview-anchor">
|
||||
<a href="/{post.slug}" class="preview-anchor">
|
||||
<article>
|
||||
<div class="article-header">
|
||||
<h2>{post.title}</h2>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import path from 'path'
|
||||
import fs from 'fs'
|
||||
|
||||
export const postsDir = 'src/routes/blog' as const
|
||||
export const postsDir = 'src/routes' as const
|
||||
|
||||
export async function listBlogPostSlugs(): Promise<string[]> {
|
||||
await fs.promises.readdir(postsDir)
|
||||
|
@ -53,9 +53,9 @@ export async function doesAssetExist(postSlug: string, assetName: string): Promi
|
|||
export async function getPost(slug: string): Promise<BlogPost | null> {
|
||||
if (!doesBlogPostExist(slug)) return null
|
||||
|
||||
const url = new URL(`protocol://-/blog/${slug}`)
|
||||
const url = new URL(`protocol://-/${slug}`)
|
||||
|
||||
const { default: post, metadata } = await import(`../routes/blog/${slug}/index.svx`)
|
||||
const { default: post, metadata } = await import(`../routes/${slug}/index.svx`)
|
||||
|
||||
const result: {
|
||||
title: string
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import type { Load } from '@sveltejs/kit'
|
||||
import { error, type Load } from '@sveltejs/kit'
|
||||
|
||||
export const prerender = true
|
||||
|
||||
|
@ -6,7 +6,12 @@ export const load: Load = async ({ params }) => {
|
|||
const { slug } = params
|
||||
if (!slug) throw new Error('No slug')
|
||||
|
||||
const page = await import(`../${slug}/index.svx`)
|
||||
let page
|
||||
try {
|
||||
page = await import(`../${slug}/index.svx`)
|
||||
} catch (e) {
|
||||
throw error(404, 'Not found')
|
||||
}
|
||||
|
||||
return {
|
||||
page: page.default,
|
|
@ -8,7 +8,7 @@
|
|||
},
|
||||
{
|
||||
"name": "mat's server scanner",
|
||||
"href": "/blog/minecraft-scanning",
|
||||
"href": "/minecraft-scanning",
|
||||
"languages": ["rust", "python", "typescript", "svelte"],
|
||||
"description": "Scanning the internet for Minecraft servers for fun."
|
||||
},
|
||||
|
|
|
@ -9,7 +9,7 @@ export const GET: RequestHandler = async ({ fetch }) => {
|
|||
return `
|
||||
<item>
|
||||
<title>${post.title}</title>
|
||||
<link>https://matdoes.dev/blog/${post.slug}</link>
|
||||
<link>https://matdoes.dev/${post.slug}</link>
|
||||
<pubDate>${post.published}</pubDate>
|
||||
</item>
|
||||
`
|
||||
|
|
15
src/routes/blog/[...path]/+server.ts
Normal file
|
@ -0,0 +1,15 @@
|
|||
import type { RequestHandler } from '@sveltejs/kit'
|
||||
|
||||
export const GET: RequestHandler = async ({ params }) => {
|
||||
console.log(params.path)
|
||||
let location = `/${params.path}`
|
||||
if (params.path == 'minecraft-server-warner') {
|
||||
location = '/matscan'
|
||||
}
|
||||
return new Response(null, {
|
||||
status: 302,
|
||||
headers: {
|
||||
Location: location,
|
||||
},
|
||||
})
|
||||
}
|
|
@ -9,7 +9,7 @@ Gemini is a protocol similar to HTTP, in that it's used for transmitting (mostly
|
|||
|
||||
Anyways, so I decided to make my website support the Gemini protocol for fun. The plan is to make it translate the HTML on my blog into Gemtext, which shouldn't be _too_ hard considering that HTML is generated from mostly markdown.
|
||||
|
||||
[Here's an example of a typical blog post I write, mostly markdown and some HTML.](https://github.com/mat-1/matdoesdev/blob/main/src/routes/blog/minecraft-scanning/index.svx)
|
||||
[Here's an example of a typical blog post I write, mostly markdown and some HTML.](https://github.com/mat-1/matdoesdev/blob/main/src/routes/minecraft-scanning/index.svx)
|
||||
|
||||
At first, I tried using the [html_parser Rust crate](https://github.com/mathiversen/html-parser) to read the HTML and flatten it out. However, I soon ran into [issue #22: Incorrectly trimming whitespaces for text nodes](https://github.com/mathiversen/html-parser/issues/22). This made text be squished with links, and while technically I could've added workarounds by having it add spaces there I figured it'd be better to avoid issues with that in the future by just using a different crate. I looked at other HTML parsing crates and decided on [tl](https://github.com/y21/tl), which does not suffer from the same issue as html_parser.
|
||||
|
|
@ -58,7 +58,7 @@
|
|||
top: 0.25em;
|
||||
}
|
||||
.minecraft-server {
|
||||
background-image: url(/blog/minecraft-scanning/minecraft-server-background.png);
|
||||
background-image: url(/minecraft-scanning/minecraft-server-background.png);
|
||||
height: 5em;
|
||||
font-family: Minecraft;
|
||||
font-size: 16px;
|
Before Width: | Height: | Size: 158 KiB After Width: | Height: | Size: 158 KiB |
Before Width: | Height: | Size: 64 KiB After Width: | Height: | Size: 64 KiB |
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 26 KiB |
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 2.4 KiB |
Before Width: | Height: | Size: 177 KiB After Width: | Height: | Size: 177 KiB |
Before Width: | Height: | Size: 146 KiB After Width: | Height: | Size: 146 KiB |
|
@ -1,8 +1,8 @@
|
|||
import projects from '../_projects.json'
|
||||
import { error, json, type RequestHandler } from '@sveltejs/kit'
|
||||
import { json, type RequestHandler } from '@sveltejs/kit'
|
||||
|
||||
export const prerender = true
|
||||
|
||||
export const GET: RequestHandler = async ({ params }) => {
|
||||
export const GET: RequestHandler = async () => {
|
||||
return json(projects)
|
||||
}
|
||||
|
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 36 KiB After Width: | Height: | Size: 36 KiB |
Before Width: | Height: | Size: 5 KiB After Width: | Height: | Size: 5 KiB |
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
|
@ -19,7 +19,7 @@ const config = {
|
|||
kit: {
|
||||
adapter: staticAdapter({}),
|
||||
prerender: {
|
||||
entries: ['*', '/blog/minecraft-scanning/minecraft-server-background.png'],
|
||||
entries: ['*', '/minecraft-scanning/minecraft-server-background.png'],
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|