1
0
mirror of https://github.com/axzilla/templui.git synced 2025-02-21 00:12:48 +00:00

refactor: clean up unused code and enhance documentation for development tools, remove mimetype stuff

This commit is contained in:
axzilla 2024-12-07 19:24:40 +07:00
parent 351cf004f3
commit e48fcf21de
2 changed files with 75 additions and 21 deletions

View File

@ -3,7 +3,7 @@ package main
import (
"fmt"
"net/http"
"path/filepath"
// "path/filepath"
"github.com/a-h/templ"
"github.com/axzilla/goilerplate/assets"
@ -54,27 +54,27 @@ func main() {
func SetupAssetsRoutes(mux *http.ServeMux) {
var isDevelopment = config.AppConfig.GoEnv != "production"
mimeTypes := map[string]string{
".css": "text/css; charset=utf-8",
".js": "application/javascript; charset=utf-8",
".svg": "image/svg+xml",
".html": "text/html; charset=utf-8",
".jpg": "image/jpeg",
".jpeg": "image/jpeg",
".png": "image/png",
".gif": "image/gif",
".woff": "font/woff",
".woff2": "font/woff2",
".ttf": "font/ttf",
".ico": "image/x-icon",
}
// mimeTypes := map[string]string{
// ".css": "text/css; charset=utf-8",
// ".js": "application/javascript; charset=utf-8",
// ".svg": "image/svg+xml",
// ".html": "text/html; charset=utf-8",
// ".jpg": "image/jpeg",
// ".jpeg": "image/jpeg",
// ".png": "image/png",
// ".gif": "image/gif",
// ".woff": "font/woff",
// ".woff2": "font/woff2",
// ".ttf": "font/ttf",
// ".ico": "image/x-icon",
// }
assetHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ext := filepath.Ext(r.URL.Path)
// ext := filepath.Ext(r.URL.Path)
if mimeType, ok := mimeTypes[ext]; ok {
w.Header().Set("Content-Type", mimeType)
}
// if mimeType, ok := mimeTypes[ext]; ok {
// w.Header().Set("Content-Type", mimeType)
// }
if isDevelopment {
w.Header().Set("Cache-Control", "no-store")

View File

@ -206,7 +206,6 @@ templ HowToUse() {
</div>
</div>
</section>
//
<section class="mb-12">
<h2 class="text-2xl font-semibold mb-4 text-primary">Base Configuration</h2>
<p class="mb-4">Goilerplate provides pre-configured styles and themes. You'll need these files in your project:</p>
@ -224,7 +223,62 @@ templ HowToUse() {
</div>
</div>
</section>
//
<section class="mb-12">
<h2 class="text-2xl font-semibold mb-4 text-primary">Development Tools</h2>
<p class="mb-4">
While not required, we recommend setting up these development tools for a better workflow with Go and Templ projects (regardless of whether you use Goilerplate):
</p>
<div class="space-y-6">
<div>
<h3 class="text-xl font-semibold mb-2">1. Air (Live Reload for Go)</h3>
<p class="mb-2">Install Air for automatic Go server rebuilds:</p>
@modules.CodeSnippet("go install github.com/cosmtrek/air@latest", "markdown")
</div>
<div>
<h3 class="text-xl font-semibold mb-2">2. Development Makefile</h3>
<p class="mb-2">Create a Makefile in your project root:</p>
@modules.CodeSnippet(`# Run templ generation in watch mode
templ:
templ generate --watch --proxy="http://localhost:8090" --open-browser=false -v
# Run air for Go hot reload
server:
air \
--build.cmd "go build -o tmp/bin/main ./main.go" \
--build.bin "tmp/bin/main" \
--build.delay "100" \
--build.exclude_dir "node_modules" \
--build.include_ext "go" \
--build.stop_on_error "false" \
--misc.clean_on_exit true
# Watch Tailwind CSS changes
tailwind:
tailwindcss -i ./assets/css/input.css -o ./assets/css/output.css --watch
# Start development server with all watchers
dev:
make -j3 templ server tailwind`, "makefile")
</div>
<div>
<h3 class="text-xl font-semibold mb-2">3. Start Development Server</h3>
<p class="mb-2">Start all development tools with a single command:</p>
@modules.CodeSnippet("make dev", "markdown")
<p class="text-sm mt-2">This will:</p>
<ul class="list-disc pl-6 text-sm space-y-1">
<li>Watch and compile Templ files</li>
<li>Start the Go server with hot reload via Air</li>
<li>Watch and compile Tailwind CSS changes</li>
</ul>
<p class="text-sm mt-2">Or run services individually:</p>
<ul class="list-disc pl-6 text-sm space-y-1">
<li>{ `make templ` } - Watch Templ files only</li>
<li>{ `make server` } - Run Go server only</li>
<li>{ `make tailwind` } - Watch Tailwind CSS only</li>
</ul>
</div>
</div>
</section>
<section class="mb-12">
<h2 class="text-2xl font-semibold mb-4 text-primary">Installation Options</h2>
<p class="mb-4">After installing the requirements, you have three ways to use Goilerplate:</p>