Daisy-RSX

repository·main·Indexed 41 days ago

https://github.com/bionic-gpt/daisy-rsx

A Dioxus implementation of the DaisyUI component library for Rust developers, primarily targeting server-side rendering. Version 0.1.59 includes components such as Card, Avatar, DropDown, Badge, and Button, and features ssg_whiz, an experimental static site generator for Rust and Dioxus.

Tokens
20K
Snippets
78
Records
93
Agent score
53%

What's inside Daisy-RSX

  1. Overview of ssg_whiz

    main
    ssg_whiz is an experimental, opinionated static site generator for Rust and Dioxus. It is designed to provide a consistent layout for marketing, documentation, and blog sites with minimal configuration. It automatically handles asset management by copying the assets/ directory and content directories (e.g., content/blog/) into the distribution directory.
  2. Create content summaries using Summary and PageSummary

    main

    Content is organized into Summary objects, which contain Category objects, which in turn contain PageSummary objects. This structure allows you to map markdown files in your content/ folder to a structured site hierarchy.

    PageSummary fields:

    • date: String date of the post.
    • title: The page title.
    • description: A brief summary.
    • folder: The subfolder name.
    • markdown: The filename (e.g., hello-world.md).
    • author: Optional author name.
    • image / open_graph_image: Optional image paths.
    let blog_summary = Summary {
        source_folder: "blog",
        categories: vec![Category {
            name: "Announcements".to_string(),
            pages: vec![PageSummary {
                date: "2026-02-06",
                title: "Hello, world",
                description: "First post from the new site.",
                folder: "hello-world",
                markdown: "hello-world.md",
                image: None,
                open_graph_image: None,
                author: Some("Ada Lovelace"),
                author_image: None,
            }],
        }],
    };
  3. Configure Tailwind CSS for Daisy-RSX

    main

    Daisy-RSX components rely on Tailwind CSS and the DaisyUI plugin. To ensure all component classes are included in your final stylesheet, you must use @source directives in your CSS file. This is especially important for classes used within component logic that might not be explicitly visible in the static HTML.

    You can use tailwind-cli-extra to compile your CSS without requiring npm.

    @import 'tailwindcss';
    @plugin "daisyui";
    
    /* Scan your Rust files for component usage */
    @source '../web-pages/**/*.rs';
    @source 'typescript/**/*.ts';
    
    /* Ensure specific Daisy UI classes are included via inline scanning */
    @source inline("modal modal-box modal-action");
  4. How to use ssg_whiz to build a site

    main

    To build a site with ssg_whiz, follow these four steps:

    1. Define SiteConfig: Specify your distribution directory (dist_dir), navigation links, footer links, site metadata, and an optional header.
    2. Build Summaries: Create Summary objects for your different content types (e.g., blog, docs, or general pages). These summaries map your markdown content to categories and pages.
    3. Provide Static Page Generators: Implement a function that returns a list of SitePage objects for bespoke, component-driven pages (like a homepage).
    4. Execute the Builder DSL: Use SiteBuilder to compose these pieces and trigger the build process.
    // High-level workflow pattern
    SiteBuilder::new(config)
        .blog(blog_summary)
        .pages(pages_summary)
        .document(DocumentSite { ... })
        .static_pages(my_site::generate_static_pages)
        .build()
        .await?;
  5. Use Daisy-RSX UI components

    main

    Daisy-RSX provides a collection of reusable UI components for Rust-based web applications. The library exports a wide range of components including layout elements, form inputs, navigation, and feedback indicators. You can import these components directly from the daisy_rsx crate.

    use daisy_rsx::{Button, Alert, Modal, Input};
  6. Configure a site with SiteConfig

    main

    The SiteConfig struct defines the global settings for your static site. Key fields include:

    • dist_dir: The directory where the generated site will be written.
    • run_server: Boolean to determine if a development server should run.
    • addr: The network address for the development server.
    • live_reload: Boolean to enable live reloading.
    • navigation_links: Links for the site navigation.
    • footer_links: Links for the site footer.
    • site_meta: Metadata for the site (e.g., SEO).
    • site_header: An optional header component.
    let config = SiteConfig {
        dist_dir: "dist".into(),
        run_server: false,
        addr: SocketAddr::from(([0, 0, 0, 0], 8080)),
        live_reload: false,
        navigation_links: my_ui::navigation_links(),
        footer_links: my_ui::footer_links(),
        site_meta: my_ui::site_meta(),
        site_header: None,
    };
  7. Use SiteBuilder to generate a static site

    main

    The SiteBuilder follows a builder pattern to configure and generate a static website. You initialize it with a SiteConfig, add content summaries (blog, pages, documents), and optionally provide a function for dynamic static pages. Finally, you call .build().await to execute the generation process.

    Key Workflow:

    1. Initialize with SiteBuilder::new(config).
    2. Attach content using .blog(), .pages(), .document(), or .documents().
    3. (Optional) Attach async static pages using .static_pages(async || { ... }).
    4. Execute the build with .build().await.
    let builder = SiteBuilder::new(config)
        .blog(blog_summary)
        .pages(pages_summary)
        .document(doc_site)
        .static_pages(|| async {
            vec![/* custom SitePage objects */]
        });
    
    builder.build().await?;