Astro Theme Pure

repository·main·Indexed 21 days ago

https://github.com/cworld1/astro-theme-pure

A high-performance, SEO-friendly blog and documentation theme for Astro (version 4.1.4). It features full-site search powered by pagefind, dynamic OG image generation, and a comprehensive suite of basic and advanced components. The theme utilizes UnoCSS as the recommended styling engine and provides an Astro integration to automatically configure sitemaps, MDX, and Markdown processing via Remark and Rehype plugins.

Tokens
34.6K
Snippets
134
Records
169
Agent score
74%

What's inside astro-theme-pure

  1. Overview of Astro Theme Pure

    main

    Astro Theme Pure is a simple, fast, and powerful blog and documentation theme built with Astro. It features a clean, responsive design optimized for high performance and SEO.

    Key Features:

    • Performance: Fast and high-performance with high Lighthouse scores.
    • Search: Full-site search powered by pagefind.
    • Navigation & SEO: Includes Sitemap, RSS feed, Table of Contents (TOC), and SEO-friendly structures.
    • Media: Dynamic Open Graph generation for posts and Mediumzoom lightbox for images.

    Components: The theme provides a variety of components that can be used within the theme or imported into other Astro projects. Note that using these components in external Astro projects requires UnoCSS.

    • Basic components: Aside, Tabs, Timeline, Steps, Spoiler, etc.
    • Advanced components: GithubCard, LinkPreview, Quote, QRCode, etc.
  2. Understand the theme file structure

    main

    The following directory structure defines the theme's organization:

    • public: Static resources copied to the root.
    • src/assets: Static resources (images, etc.).
    • src/components: UI components (e.g., Card, Collapse, Spoiler).
    • src/layouts: Basic site layouts.
    • src/pages: Route definitions (e.g., 404, about, blog, docs, index).
    • src/plugins: Extended theme plugins.
    • src/types: TypeScript definitions.
    • src/utils: Utility functions.
    • src/site.config.ts: Main theme configuration file.
    • astro.config.ts: Astro configuration.
    • eslint.config.mjs: ESLint configuration.
    • prettier.config.mjs: Prettier configuration.
    • uno.config.ts: UnoCSS configuration.
    • tsconfig.json: TypeScript configuration.
    • package.json: Package information.
  3. Understand file-based routing in Astro

    main

    Astro uses the file structure within the src/pages/ directory to generate website routes. Every file in this directory automatically becomes a page.

    Route Mapping Examples

    • src/pages/index.astro $\rightarrow$ /
    • src/pages/about.astro $\rightarrow$ /about
    • src/pages/about/index.astro $\rightarrow$ /about
    • src/pages/about/me.astro $\rightarrow$ /about/me
    • src/pages/posts/1.md $\rightarrow$ /posts/1
  4. Trigger a Toast notification

    main

    Toast notifications are triggered by dispatching a custom browser event named 'toast'. You can trigger this from any component (like a Button) using document.dispatchEvent.

    Event Detail Shape:

    • message: The text content of the toast.
    • time: Duration in milliseconds.
    // Example: Triggering a toast via a button click
    <Button
      title='Click Me'
      onClick={`document.dispatchEvent(
        new CustomEvent('toast', {
          detail: {
            message: 'Hello from toast!',
            time: 5000
          }
        })
      )`}
    />
  5. Author Markdown and MDX content

    main

    Astro Theme Pure supports .md and .mdx files by default. You can write content directly in these files or fetch it from a headless CMS.

    Markdown Frontmatter Schema

    When creating blog posts (e.g., in src/content/blog/), use the following frontmatter keys:

    • title: (Required) String, max 60 characters.
    • description: (Required) String, 10 to 160 characters.
    • publishDate: (Required) Date format (e.g., '2024-11-30 00:08:00').
    • tags: Array of strings.
    • heroImage: Object for the article's featured image.
      • src: Path to local image or remote URL.
      • alt: Alt text for the image.
      • color: Hex color code.
      • inferSize: (Boolean) Set to true if using a remote image to automatically determine dimensions.
      • width / height: (Optional) Specify dimensions for remote images.
    • draft: (Boolean) If true, the post only shows in development.
    • language: (String) The language of the article.
    • comment: (Boolean) Set to false to disable comments for this specific post, even if enabled globally in site-config.

    Asset Management

    To keep assets organized, you can create a folder named after your article slug (e.g., src/content/blog/my-post/) and place an index.md file inside it along with your images. Alternatively, ensure local images used in heroImage are in the same folder as the .md file.

    Quick Start

    You can use a built-in script to scaffold a new article by running: bun pure new <post-slug>

    ---
    title: 'First Article'
    description: 'I like writing articles.'
    publishDate: '2024-11-30 00:08:00'
    tags:
      - Markdown
    heroImage: { src: './thumbnail.jpg', alt: 'an image targeting my article', color: '#B4C6DA' }
    draft: false
    language: 'English'
    comment: true
    ---
    
    ## This is a title
    
    This is a paragraph.
  6. Update Astro Theme Pure

    main

    Updating the theme can be complex due to frequent updates and breaking changes. Depending on how you initialized your project, use one of the following methods:

    Rebase

    If you created your project by forking the theme repository, you can simply rebase your fork onto the latest version of the theme repository.

    Manual Merge

    If your git histories have diverged, you must merge the theme repository into your project manually. For Windows users, WinMerge is recommended. Use a filter list to manage which files to include/exclude during the diff process to avoid conflicts with your own content (like src/content/blog).

  7. Use web images for `heroImage`

    main

    To use external web images for the heroImage property in your content, you must include inferSize: true in the configuration object. This allows the theme to correctly determine the image dimensions for layout purposes.

    heroImage:
      { src: 'https://img.tukuppt.com/ad_preview/00/15/09/5e715a320b68e.jpg!/fw/980', inferSize: true }
  8. Use Package Mode for breaking changes

    main

    If you need to make fundamental, breaking changes to the theme's underlying logic, you can use 'Package Mode'. This involves linking a local version of the theme source code to your project using your package manager's linking command. This allows you to treat the theme as part of your own source code.

    Warning: This method increases project complexity and makes future theme updates more difficult. Use it only when necessary.

    Steps:

    1. Ensure you have the original theme source code locally.
    2. Use a package manager to link the local source to your project (e.g., npm link, pnpm link, or bun link).
    # Example linking commands
    
    # Using Bun
    bun link
    
    # Using NPM
    npm link
    
    # Using PNPM
    pnpm link
  9. Use Shiki code blocks in Astro, MD, and MDX

    main

    You can render code blocks using the built-in Astro Code component or standard Markdown syntax.

    In .astro files

    Import Code from astro:components and use it as a component:

    ---
    import { Code } from 'astro:components'
    ---
    
    <Code lang='shell' code={`git log --oneline`} />

    In .md and .mdx files

    Use standard Markdown fenced code blocks:

    ```shell
    git log --oneline
    ---
    import { Code } from 'astro:components'
    ---
    
    <Code lang='shell' code={`git log --oneline`} />