roger pence

Search
Advanced Search
Folder to search:
Limit search to one of these properties:

    Markdown post objects for Svelte web apps

    See also:

    Link
    Predeploy objects creation

    All markdown posts have this frontmatter:

    ---
    title: A better way to dispose objects
    description: This article explains how to...
    tags:
      - visual-rpg
    date_published: '2025-11-21'
    date_added: '2025-11-21'
    date_updated: '2025-11-21'
    draft: false
    hidden: false
    pinned: true
    see_also: null
    ---
    

    For both build- and run- time, all markdown posts are collected first into an array of post objects. This object array is used to create two other object arrays that are used for document tag management and search engine indexing.

    This array of objects is created at build time and persited in this file:

    src\lib\data\transient\posts-markdown-objects.ts
    

    When this file is created, each document's frontmatter is checked against this schema to ensure typesafety for the resulting objects. This Zod object defines the schema for a post's frontmatter and the corresponding TS type is exported.

    const ASNAPostSchema = z.object({
    	title: z.string().min(1, 'Title cannot be empty'),
    	description: z.string().min(1, 'Description cannot be empty'),
    	tags: z.array(z.string().min(1, 'Tag cannot be empty')), 
    	date_published: z.union([z.date(), z.string()]),
    	date_added: z.union([z.date(), z.string()]),
    	date_updated: z.union([z.date(), z.string()]),
    	draft: z.boolean().nullish(),
    	hidden: z.boolean().nullish(),
    	pinned: z.boolean().nullish(),
    	see_also: z.union([z.array(z.string()), z.null()])
    });
    
    export type ASNAPost = z.infer<typeof ASNAPostSchema>;
    

    An entire markdown post is represented by this TS type:

    export type FullMarkdown<T> = {
    	dirent: DirectoryEntry;
    	markdownObject: {
    		frontMatter: T;
    		content: string;
    	};
    };
    

    An example corresponding TS object for the markdown post:

    {
        "dirent": {
            "name": "a-better-way-to-dispose-objects.en.md",
            "path": "../markdown/kb",
            "parentPath": "../markdown/kb"
        },
        "markdownObject": {
            "frontMatter": {
                "title": "A better way to dispose objects",
                "description": "This article explains how to...",
                "tags": [
                    "visual-rpg"
                ],
                "date_published": "2025-11-21T00:00:00.000Z",
                "date_added": "2025-11-21T00:00:00.000Z",
                "date_updated": "2025-11-21T00:00:00.000Z",
                "draft": false,
                "hidden": false,
                "pinned": true,
                "see_also": null
            },
            "content": "\nAn often-overlooked feature.."
        }
    },
    

    A single markdown post object is typed as FullMarkdown<ASNAPost> and the full array of markdown post objects is typed as FullMarkdown<ASNAPost>[]