From 5c0890fe38b0dcc6b85f00f52d1b37fe14b57a08 Mon Sep 17 00:00:00 2001 From: thomasborgen Date: Sat, 27 Dec 2025 21:24:02 +0100 Subject: [PATCH 1/2] Add tailwind+daisyui section --- docs/daisyui.md | 96 +++++++++++++++++++++++++++++++++++++++++++ docs/fastapi/index.md | 2 +- docs/index.md | 4 +- 3 files changed, 99 insertions(+), 3 deletions(-) create mode 100644 docs/daisyui.md diff --git a/docs/daisyui.md b/docs/daisyui.md new file mode 100644 index 0000000..1e6bddc --- /dev/null +++ b/docs/daisyui.md @@ -0,0 +1,96 @@ +# CSS - DaisyUI, Tailwind + +In this guide the folder my app is just called `server`, whenever it is used, replace it with your app folder. This is the folder that contains the `main.py`(normally) file that has the `app = FastAPI()` variable in it. We've highlighted where you need to do changes. + +## 1. Download and setup tailwind cli + +DaisyUI has a quick setup that is easy to follow. + +[https://daisyui.com/docs/install/standalone/](https://daisyui.com/docs/install/standalone/) + +This also downloads the daisyui mjs file and creates `input.css` and `output.css` files. You can just delete the `output.css` file for now. + + +## 2. Make a tailwind setup file + +This fils should be in the root of your project folder with the name `input.css` + +If you got one in step 1, just make sure it looks something like below. + +```css hl_lines="1 7" +@import "tailwindcss" source("./server"); + +@source not "./tailwindcss"; +@source not "./daisyui{,*}.mjs"; + +@plugin "./daisyui.mjs" { + themes: cupcake; +} +``` + +replace `"./server"` with the name of your app folder + +!!! tip + You can change the theme to the one you like, just replace `cupcake` with a name you find [in this list](https://daisyui.com/docs/themes/) + + +## 3 Compile the new tailwind to use + +```sh +./tailwindcss -i ./input.css -o ./server/static/css/server.css +``` + +!!! note + Change `server` with the name of your app. The folder that contains tha main.py that has the wsgi app variable. + +!!! tip + add `-m` flag to minify the css output + +If that doesn't work try to make the tailwind file executable with: + +```sh +chmod +x tailwindcss +``` + +If that doesnt work follow this guide and try again, try to figure it out and post an update with the fix or the issue at the [issue tracker](https://github.com/thomasborgen/hypermedia/issues) + + +## 4. Add static file handler to the FastAPI app + +in `main.py` add the following, making sure to change `server` with your app folders name first + +```python +app.mount("/static", StaticFiles(directory="server/static/"), name="static") +``` + +## 5. Add the script tag to load the css in your base html. + +```python hl_lines="12 21" +def get_base() -> Element: + """Create the base page.""" + return ElementList( + Doctype(), + Html( + Head( + Meta(charset="UTF-8"), + Meta( + name="viewport", + content="width=device-width, initial-scale=1.0", + ), + Link(rel="stylesheet", href="/static/css/server.css"), + Title("Server - home"), + slot="head", + ), + Body( + Header(), + Main(id="main", slot="main") + ), + lang="no-nb", + data_theme="cupcake", # type: ignore + ), + ) +``` + +Change `/static/css/server.css` if you chose a different folder structure. + +Change the `cupcake` part of `data_theme="cupcake"` to whichever theme you want. diff --git a/docs/fastapi/index.md b/docs/fastapi/index.md index d46ede1..fca3b3d 100644 --- a/docs/fastapi/index.md +++ b/docs/fastapi/index.md @@ -4,7 +4,7 @@ Hypermedia can be used with any framework, but was created with FastAPI in mind In FastAPI you create function and decorate them to create routes. When FastAPI gets a request it looks for a function that is decorated with a path that matches the url. -This section assumes you have read the [html](/html) section of the documentation. +This section assumes you have read the [htmx](../htmx.md) section of the documentation. ## Returning html in FastAPI diff --git a/docs/index.md b/docs/index.md index ba532ae..4c60777 100644 --- a/docs/index.md +++ b/docs/index.md @@ -82,7 +82,7 @@ This was just the way we wanted to write html with python. We didn't want to hav Add issues, ask good questions. Come with good suggestions <3 -[check the contibuting section](/hypermedia/contributing) +[check the contibuting section](contributing.md) ## Installation @@ -99,4 +99,4 @@ uv add hypermedia ``` -What to do next? head over to the [quickstart](/hypermedia/quickstart) section! +What to do next? head over to the [quickstart](quickstart.md) section! From 9fad201bd9918eb197d2f7984a79c2d0f687fe86 Mon Sep 17 00:00:00 2001 From: thomasborgen Date: Sat, 27 Dec 2025 21:27:49 +0100 Subject: [PATCH 2/2] Add changelog entry --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 08d0798..9e15eb8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,11 @@ ## Latest Changes +### Docs + +Released some documentation with mkdocs material +* Quickstart, Contributing, FastAPI, HTMX, and Tailwind+DaisyUI sections added. + ## Version 5.4.0 ### Features