Skip to content

Conversation

grmbyrn
Copy link
Collaborator

@grmbyrn grmbyrn commented Mar 22, 2025

Refactor Blog Section: Transition from Markdown to SvelteKit-based Posts

  • Old structure: Previously, each blog post was represented as a Markdown file inside the /blog directory. The content was accessed via dynamic routes like blog/[slug].

  • New structure: Now, each blog post is stored in its own directory under src/routes/blog/{post-slug}, where {post-slug} is the specific slug for each blog post (e.g., src/routes/blog/benchmarking-the-torrust-bittorrent-tracker). Each post has a +page.svelte file that handles the display logic for that specific post.

  • Metadata handling:

    • Introduced a metadata.ts file in each blog post directory to store post-specific data such as title, excerpt, tags, contributor, and cover image.
    • A global metadata.ts file in the lib/data directory fetches all the blog post metadata from static/blogMetadata.json, which is generated by a custom script (scripts/generateMetadata.ts).
    • The metadata is read and parsed to fetch details such as the post title, contributor, and tags, then made available for rendering in the +page.svelte component for each post.
  • generateMetadata.ts script: Added a new script that reads all metadata.ts files from the src/routes/blog directory, collects metadata for each blog post, and generates a static/blogMetadata.json file to serve as a centralized metadata source.

  • Benefits:

    • Improved scalability and maintainability by transitioning from Markdown to SvelteKit-native routes and metadata.
    • Simplified data flow and fetching for blog posts, as metadata is now dynamically loaded and cached.
    • Enhanced flexibility in post structuring and content management, supporting richer features beyond the Markdown-based setup.

@grmbyrn grmbyrn requested a review from josecelano March 23, 2025 09:08
@josecelano
Copy link
Member

ACK 004b6f8

@josecelano josecelano merged commit e0bd5b6 into torrust:develop Mar 24, 2025
1 check passed
@grmbyrn grmbyrn deleted the refactor/blog-to-sveltekit branch March 24, 2025 10:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants