Re-worked stylegen
This commit is contained in:
parent
7463d1a252
commit
00bb8d776d
25 changed files with 95 additions and 77 deletions
|
@ -6,7 +6,7 @@ tmp_dir = "tmp"
|
|||
args_bin = ["-ip", "127.0.0.1", "-port", "3000"]
|
||||
bin = "./tmp/main"
|
||||
pre_cmd = []
|
||||
cmd = "go build -o ./tmp/main . & cd lib/stylegen && ./gen.sh"
|
||||
cmd = "go build -o ./tmp/main . & cd lib/stylegen && ./gen.sh -e html -d ../../pages/templates -o ../../public/css"
|
||||
delay = 1000
|
||||
exclude_dir = ["assets", "tmp", "vendor", "testdata", "lib/stylegen"]
|
||||
exclude_file = []
|
||||
|
|
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -5,4 +5,4 @@ airbin
|
|||
tmp/
|
||||
*.rdb
|
||||
.DS_Store
|
||||
tailwind.config.*.js
|
||||
tailwind.config.js
|
31
lib/sse.go
31
lib/sse.go
|
@ -17,7 +17,6 @@ type SSEServerType struct {
|
|||
}
|
||||
|
||||
var SSEServer *SSEServerType
|
||||
var mutex = &sync.Mutex{}
|
||||
|
||||
func init() {
|
||||
SSEServer = &SSEServerType{
|
||||
|
@ -90,24 +89,21 @@ func SetSSEHeaders(c echo.Context) {
|
|||
}
|
||||
|
||||
func HandleIncomingMessages(c echo.Context, pubsub pubsub.PubSubMessage, client chan string) {
|
||||
// Create a new context that is not tied to the client's request context
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel() // Cancel the context when the function returns
|
||||
defer cancel()
|
||||
|
||||
// Use a separate goroutine to monitor the client's request context
|
||||
go func() {
|
||||
<-c.Request().Context().Done()
|
||||
cancel() // Cancel the context when the client disconnects
|
||||
cancel()
|
||||
}()
|
||||
|
||||
var mutex sync.Mutex
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
// The context has been canceled, either by the client disconnecting
|
||||
// or by the function returning. Stop trying to send messages.
|
||||
return
|
||||
default:
|
||||
// The client is still connected. Continue processing messages.
|
||||
msg, err := pubsub.ReceiveMessage(ctx)
|
||||
if err != nil {
|
||||
log.Printf("Failed to receive message: %v", err)
|
||||
|
@ -117,17 +113,15 @@ func HandleIncomingMessages(c echo.Context, pubsub pubsub.PubSubMessage, client
|
|||
data := fmt.Sprintf("data: %s\n\n", msg.Payload)
|
||||
|
||||
mutex.Lock()
|
||||
_, err = c.Response().Write([]byte(data))
|
||||
mutex.Unlock()
|
||||
defer mutex.Unlock()
|
||||
|
||||
if err != nil {
|
||||
log.Printf("Failed to write message: %v", err)
|
||||
return // Stop processing if an error occurs
|
||||
}
|
||||
|
||||
// Check if the ResponseWriter is nil before trying to flush it
|
||||
if c.Response().Writer != nil {
|
||||
// Check if the ResponseWriter implements http.Flusher before calling Flush
|
||||
_, err = c.Response().Write([]byte(data))
|
||||
if err != nil {
|
||||
log.Printf("Failed to write message: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
flusher, ok := c.Response().Writer.(http.Flusher)
|
||||
if ok {
|
||||
flusher.Flush()
|
||||
|
@ -135,7 +129,8 @@ func HandleIncomingMessages(c echo.Context, pubsub pubsub.PubSubMessage, client
|
|||
log.Println("Failed to flush: ResponseWriter does not implement http.Flusher")
|
||||
}
|
||||
} else {
|
||||
log.Println("Failed to flush: ResponseWriter is nil")
|
||||
log.Println("Failed to write: ResponseWriter is nil")
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,26 @@
|
|||
#!/bin/sh
|
||||
#!/bin/bash
|
||||
|
||||
# Parse command-line arguments
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
-e|--extensions)
|
||||
EXTENSIONS="$2"
|
||||
shift; shift
|
||||
;;
|
||||
-d|--directory)
|
||||
DIRECTORY="$2"
|
||||
shift; shift
|
||||
;;
|
||||
-o|--output-dir)
|
||||
OUTPUT_DIR="$2"
|
||||
shift; shift
|
||||
;;
|
||||
*)
|
||||
echo "Unknown argument: $1"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
OS=$(uname -s)
|
||||
ARCH=$(uname -m)
|
||||
|
@ -41,39 +63,52 @@ else
|
|||
chmod +x $BINARY
|
||||
fi
|
||||
|
||||
echo $BINARY
|
||||
echo "Extensions: $EXTENSIONS"
|
||||
echo "Directory: $DIRECTORY"
|
||||
echo "Output Directory: $OUTPUT_DIR"
|
||||
|
||||
# Infer pages from .html files in the pages directory
|
||||
PAGES=$(ls ../../pages/templates/*.html | xargs -n 1 basename | sed 's/\.[^.]*$//')
|
||||
# Set default values if not provided
|
||||
OUTPUT_DIR="${OUTPUT_DIR:-../../public/css}"
|
||||
DIRECTORY="${DIRECTORY:-.}"
|
||||
|
||||
# Run the binary for each page
|
||||
for PAGE in $PAGES; do
|
||||
(
|
||||
# Detect which partials are being used in this page
|
||||
PARTIALS=$(grep -o -E '{{template "[^"]+' ../../pages/templates/${PAGE}.html | cut -d'"' -f2 | xargs -I{} echo \"../../pages/templates/partials/{}.html\")
|
||||
if [[ -z "$EXTENSIONS" ]]; then
|
||||
echo "No extensions provided."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Generate an array of partials and join them with commas
|
||||
PARTIALS_ARRAY=$(echo $PARTIALS | tr ' ' ',')
|
||||
# Initialize an array for name conditions
|
||||
name_conditions=()
|
||||
|
||||
# Always include the "header" partial and any other partials that are always used
|
||||
PARTIALS_ARRAY=\"../../pages/templates/partials/header.html\",\"../../pages/templates/partials/global.html\",$PARTIALS_ARRAY
|
||||
|
||||
# Generate Tailwind config for this page
|
||||
echo "module.exports = {
|
||||
content: [\"../../pages/templates/${PAGE}.html\", \"../../pages/templates/layouts/*.html\", $PARTIALS_ARRAY],
|
||||
theme: {
|
||||
extend: {},
|
||||
},
|
||||
daisyui: {
|
||||
themes: [\"night\"],
|
||||
},
|
||||
plugins: [require('daisyui'), require('@tailwindcss/typography')],
|
||||
}" > tailwind.config.${PAGE}.js
|
||||
|
||||
# Run the binary with the generated config
|
||||
$BINARY build -i ./base.css -c tailwind.config.${PAGE}.js -o ../../public/css/styles.${PAGE}.css --minify
|
||||
) &
|
||||
# Assuming $EXTENSIONS is a comma-separated list of extensions
|
||||
IFS=',' read -ra ADDR <<< "$EXTENSIONS"
|
||||
for ext in "${ADDR[@]}"; do
|
||||
name_conditions+=(-name "*.$ext")
|
||||
done
|
||||
|
||||
# Use find with the array of conditions
|
||||
INCLUDE_FILES=$(find "$DIRECTORY" -type f \( "${name_conditions[@]}" \))
|
||||
|
||||
echo "Files found: $INCLUDE_FILES"
|
||||
|
||||
# Optionally, remove leading './' if necessary
|
||||
INCLUDE_FILES=$(echo "$INCLUDE_FILES" | sed 's|^\./||')
|
||||
|
||||
INCLUDE_FILES_ARRAY=$(echo "$INCLUDE_FILES" | awk '{printf "\"%s\",", $0}' | sed 's/,$//')
|
||||
|
||||
# Generate Tailwind config
|
||||
echo "module.exports = {
|
||||
content: [$INCLUDE_FILES_ARRAY],
|
||||
theme: {
|
||||
extend: {},
|
||||
},
|
||||
daisyui: {
|
||||
themes: [\"night\"],
|
||||
},
|
||||
plugins: [require('daisyui'), require('@tailwindcss/typography')],
|
||||
}" > tailwind.config.js
|
||||
|
||||
# Run the binary with the generated config
|
||||
$BINARY build -i ./base.css -c tailwind.config.js -o "${OUTPUT_DIR}/styles.css" --minify
|
||||
|
||||
# Wait for all background processes to finish
|
||||
wait
|
|
@ -7,7 +7,7 @@ Atridad Lahiji // Blog
|
|||
{{end}}
|
||||
|
||||
{{define "head"}}
|
||||
<link rel="stylesheet" href="/public/css/styles.blog.css" />
|
||||
<link rel="stylesheet" href="/public/css/styles.css" />
|
||||
{{end}}
|
||||
|
||||
{{define "main"}}
|
||||
|
@ -19,4 +19,4 @@ Atridad Lahiji // Blog
|
|||
{{end}}
|
||||
|
||||
{{define "foot"}}
|
||||
{{end}}
|
||||
{{end}}
|
|
@ -7,20 +7,17 @@ Atridad Lahiji // [SOMEPAGE]
|
|||
{{end}}
|
||||
|
||||
{{define "head"}}
|
||||
<link rel="stylesheet" href="/public/css/styles.[SOMEPAGE].css" />
|
||||
<link rel="stylesheet" href="/public/css/styles.css" />
|
||||
{{end}}
|
||||
|
||||
{{define "main"}}
|
||||
<h1 class="text-4xl font-extrabold text-white sm:text-8xl">
|
||||
New <span
|
||||
class="bg-gradient-to-r from-pink-500 to-blue-500 bg-clip-text text-transparent"
|
||||
>Page</span
|
||||
>
|
||||
</h1>
|
||||
<h1 class="text-4xl font-extrabold text-white sm:text-8xl">
|
||||
New <span class="bg-gradient-to-r from-pink-500 to-blue-500 bg-clip-text text-transparent">Page</span>
|
||||
</h1>
|
||||
{{end}}
|
||||
|
||||
{{define "foot"}}
|
||||
<script src="/public/js/htmx.base.js"></script>
|
||||
<script src="/public/js/htmx.sse.js"></script>
|
||||
<script src="/public/js/hyperscript.js"></script>
|
||||
{{end}}
|
||||
{{end}}
|
|
@ -7,7 +7,7 @@ Atridad Lahiji // Root
|
|||
{{end}}
|
||||
|
||||
{{define "head"}}
|
||||
<link rel="stylesheet" href="/public/css/styles.home.css" />
|
||||
<link rel="stylesheet" href="/public/css/styles.css" />
|
||||
{{end}}
|
||||
|
||||
{{define "main"}}
|
||||
|
|
|
@ -7,7 +7,7 @@ Atridad Lahiji // Post
|
|||
{{end}}
|
||||
|
||||
{{define "head"}}
|
||||
<link rel="stylesheet" href="/public/css/styles.post.css" />
|
||||
<link rel="stylesheet" href="/public/css/styles.css" />
|
||||
{{end}}
|
||||
|
||||
{{define "main"}}
|
||||
|
|
|
@ -7,7 +7,7 @@ Atridad Lahiji // Projects
|
|||
{{end}}
|
||||
|
||||
{{define "head"}}
|
||||
<link rel="stylesheet" href="/public/css/styles.projects.css" />
|
||||
<link rel="stylesheet" href="/public/css/styles.css" />
|
||||
{{end}}
|
||||
|
||||
{{define "main"}}
|
||||
|
|
|
@ -7,7 +7,7 @@ Atridad Lahiji // Talks
|
|||
{{end}}
|
||||
|
||||
{{define "head"}}
|
||||
<link rel="stylesheet" href="/public/css/styles.talks.css" />
|
||||
<link rel="stylesheet" href="/public/css/styles.css" />
|
||||
{{end}}
|
||||
|
||||
{{define "main"}}
|
||||
|
|
|
@ -7,7 +7,7 @@ Atridad Lahiji // Testimonials
|
|||
{{end}}
|
||||
|
||||
{{define "head"}}
|
||||
<link rel="stylesheet" href="/public/css/styles.testimonials.css" />
|
||||
<link rel="stylesheet" href="/public/css/styles.css" />
|
||||
{{end}}
|
||||
|
||||
{{define "main"}}
|
||||
|
|
|
@ -7,7 +7,7 @@ Atridad Lahiji // Tools
|
|||
{{end}}
|
||||
|
||||
{{define "head"}}
|
||||
<link rel="stylesheet" href="/public/css/styles.tools.css" />
|
||||
<link rel="stylesheet" href="/public/css/styles.css" />
|
||||
{{end}}
|
||||
|
||||
{{define "main"}}
|
||||
|
|
|
@ -7,7 +7,7 @@ Atridad Lahiji // Tools // Resizer
|
|||
{{end}}
|
||||
|
||||
{{define "head"}}
|
||||
<link rel="stylesheet" href="/public/css/styles.tools.resize.css" />
|
||||
<link rel="stylesheet" href="/public/css/styles.css" />
|
||||
{{end}}
|
||||
|
||||
{{define "main"}}
|
||||
|
|
|
@ -5,7 +5,7 @@ Atridad Lahiji // Tools // SSE Demo
|
|||
{{end}}
|
||||
|
||||
{{define "head"}}
|
||||
<link rel="stylesheet" href="/public/css/styles.tools.ssedemo.css" />
|
||||
<link rel="stylesheet" href="/public/css/styles.css" />
|
||||
{{end}}
|
||||
|
||||
{{define "main"}}
|
||||
|
|
1
public/css/styles.blog.css
vendored
1
public/css/styles.blog.css
vendored
File diff suppressed because one or more lines are too long
1
public/css/styles.css
vendored
Normal file
1
public/css/styles.css
vendored
Normal file
File diff suppressed because one or more lines are too long
1
public/css/styles.example.css
vendored
1
public/css/styles.example.css
vendored
File diff suppressed because one or more lines are too long
1
public/css/styles.home.css
vendored
1
public/css/styles.home.css
vendored
File diff suppressed because one or more lines are too long
1
public/css/styles.post.css
vendored
1
public/css/styles.post.css
vendored
File diff suppressed because one or more lines are too long
1
public/css/styles.projects.css
vendored
1
public/css/styles.projects.css
vendored
File diff suppressed because one or more lines are too long
1
public/css/styles.talks.css
vendored
1
public/css/styles.talks.css
vendored
File diff suppressed because one or more lines are too long
1
public/css/styles.testimonials.css
vendored
1
public/css/styles.testimonials.css
vendored
File diff suppressed because one or more lines are too long
1
public/css/styles.tools.css
vendored
1
public/css/styles.tools.css
vendored
File diff suppressed because one or more lines are too long
1
public/css/styles.tools.resize.css
vendored
1
public/css/styles.tools.resize.css
vendored
File diff suppressed because one or more lines are too long
1
public/css/styles.tools.ssedemo.css
vendored
1
public/css/styles.tools.ssedemo.css
vendored
File diff suppressed because one or more lines are too long
Loading…
Add table
Reference in a new issue