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"]
|
args_bin = ["-ip", "127.0.0.1", "-port", "3000"]
|
||||||
bin = "./tmp/main"
|
bin = "./tmp/main"
|
||||||
pre_cmd = []
|
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
|
delay = 1000
|
||||||
exclude_dir = ["assets", "tmp", "vendor", "testdata", "lib/stylegen"]
|
exclude_dir = ["assets", "tmp", "vendor", "testdata", "lib/stylegen"]
|
||||||
exclude_file = []
|
exclude_file = []
|
||||||
|
|
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -5,4 +5,4 @@ airbin
|
||||||
tmp/
|
tmp/
|
||||||
*.rdb
|
*.rdb
|
||||||
.DS_Store
|
.DS_Store
|
||||||
tailwind.config.*.js
|
tailwind.config.js
|
25
lib/sse.go
25
lib/sse.go
|
@ -17,7 +17,6 @@ type SSEServerType struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
var SSEServer *SSEServerType
|
var SSEServer *SSEServerType
|
||||||
var mutex = &sync.Mutex{}
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
SSEServer = &SSEServerType{
|
SSEServer = &SSEServerType{
|
||||||
|
@ -90,24 +89,21 @@ func SetSSEHeaders(c echo.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func HandleIncomingMessages(c echo.Context, pubsub pubsub.PubSubMessage, client chan string) {
|
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())
|
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() {
|
go func() {
|
||||||
<-c.Request().Context().Done()
|
<-c.Request().Context().Done()
|
||||||
cancel() // Cancel the context when the client disconnects
|
cancel()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
var mutex sync.Mutex
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
// The context has been canceled, either by the client disconnecting
|
|
||||||
// or by the function returning. Stop trying to send messages.
|
|
||||||
return
|
return
|
||||||
default:
|
default:
|
||||||
// The client is still connected. Continue processing messages.
|
|
||||||
msg, err := pubsub.ReceiveMessage(ctx)
|
msg, err := pubsub.ReceiveMessage(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Failed to receive message: %v", err)
|
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)
|
data := fmt.Sprintf("data: %s\n\n", msg.Payload)
|
||||||
|
|
||||||
mutex.Lock()
|
mutex.Lock()
|
||||||
_, err = c.Response().Write([]byte(data))
|
defer mutex.Unlock()
|
||||||
mutex.Unlock()
|
|
||||||
|
|
||||||
|
if c.Response().Writer != nil {
|
||||||
|
_, err = c.Response().Write([]byte(data))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Failed to write message: %v", err)
|
log.Printf("Failed to write message: %v", err)
|
||||||
return // Stop processing if an error occurs
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
|
||||||
flusher, ok := c.Response().Writer.(http.Flusher)
|
flusher, ok := c.Response().Writer.(http.Flusher)
|
||||||
if ok {
|
if ok {
|
||||||
flusher.Flush()
|
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")
|
log.Println("Failed to flush: ResponseWriter does not implement http.Flusher")
|
||||||
}
|
}
|
||||||
} else {
|
} 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)
|
OS=$(uname -s)
|
||||||
ARCH=$(uname -m)
|
ARCH=$(uname -m)
|
||||||
|
@ -41,26 +63,41 @@ else
|
||||||
chmod +x $BINARY
|
chmod +x $BINARY
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo $BINARY
|
echo "Extensions: $EXTENSIONS"
|
||||||
|
echo "Directory: $DIRECTORY"
|
||||||
|
echo "Output Directory: $OUTPUT_DIR"
|
||||||
|
|
||||||
# Infer pages from .html files in the pages directory
|
# Set default values if not provided
|
||||||
PAGES=$(ls ../../pages/templates/*.html | xargs -n 1 basename | sed 's/\.[^.]*$//')
|
OUTPUT_DIR="${OUTPUT_DIR:-../../public/css}"
|
||||||
|
DIRECTORY="${DIRECTORY:-.}"
|
||||||
|
|
||||||
# Run the binary for each page
|
if [[ -z "$EXTENSIONS" ]]; then
|
||||||
for PAGE in $PAGES; do
|
echo "No extensions provided."
|
||||||
(
|
exit 1
|
||||||
# Detect which partials are being used in this page
|
fi
|
||||||
PARTIALS=$(grep -o -E '{{template "[^"]+' ../../pages/templates/${PAGE}.html | cut -d'"' -f2 | xargs -I{} echo \"../../pages/templates/partials/{}.html\")
|
|
||||||
|
|
||||||
# Generate an array of partials and join them with commas
|
# Initialize an array for name conditions
|
||||||
PARTIALS_ARRAY=$(echo $PARTIALS | tr ' ' ',')
|
name_conditions=()
|
||||||
|
|
||||||
# Always include the "header" partial and any other partials that are always used
|
# Assuming $EXTENSIONS is a comma-separated list of extensions
|
||||||
PARTIALS_ARRAY=\"../../pages/templates/partials/header.html\",\"../../pages/templates/partials/global.html\",$PARTIALS_ARRAY
|
IFS=',' read -ra ADDR <<< "$EXTENSIONS"
|
||||||
|
for ext in "${ADDR[@]}"; do
|
||||||
|
name_conditions+=(-name "*.$ext")
|
||||||
|
done
|
||||||
|
|
||||||
# Generate Tailwind config for this page
|
# 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 = {
|
echo "module.exports = {
|
||||||
content: [\"../../pages/templates/${PAGE}.html\", \"../../pages/templates/layouts/*.html\", $PARTIALS_ARRAY],
|
content: [$INCLUDE_FILES_ARRAY],
|
||||||
theme: {
|
theme: {
|
||||||
extend: {},
|
extend: {},
|
||||||
},
|
},
|
||||||
|
@ -68,12 +105,10 @@ for PAGE in $PAGES; do
|
||||||
themes: [\"night\"],
|
themes: [\"night\"],
|
||||||
},
|
},
|
||||||
plugins: [require('daisyui'), require('@tailwindcss/typography')],
|
plugins: [require('daisyui'), require('@tailwindcss/typography')],
|
||||||
}" > tailwind.config.${PAGE}.js
|
}" > tailwind.config.js
|
||||||
|
|
||||||
# Run the binary with the generated config
|
# Run the binary with the generated config
|
||||||
$BINARY build -i ./base.css -c tailwind.config.${PAGE}.js -o ../../public/css/styles.${PAGE}.css --minify
|
$BINARY build -i ./base.css -c tailwind.config.js -o "${OUTPUT_DIR}/styles.css" --minify
|
||||||
) &
|
|
||||||
done
|
|
||||||
|
|
||||||
# Wait for all background processes to finish
|
# Wait for all background processes to finish
|
||||||
wait
|
wait
|
|
@ -7,7 +7,7 @@ Atridad Lahiji // Blog
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{define "head"}}
|
{{define "head"}}
|
||||||
<link rel="stylesheet" href="/public/css/styles.blog.css" />
|
<link rel="stylesheet" href="/public/css/styles.css" />
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{define "main"}}
|
{{define "main"}}
|
||||||
|
|
|
@ -7,15 +7,12 @@ Atridad Lahiji // [SOMEPAGE]
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{define "head"}}
|
{{define "head"}}
|
||||||
<link rel="stylesheet" href="/public/css/styles.[SOMEPAGE].css" />
|
<link rel="stylesheet" href="/public/css/styles.css" />
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{define "main"}}
|
{{define "main"}}
|
||||||
<h1 class="text-4xl font-extrabold text-white sm:text-8xl">
|
<h1 class="text-4xl font-extrabold text-white sm:text-8xl">
|
||||||
New <span
|
New <span class="bg-gradient-to-r from-pink-500 to-blue-500 bg-clip-text text-transparent">Page</span>
|
||||||
class="bg-gradient-to-r from-pink-500 to-blue-500 bg-clip-text text-transparent"
|
|
||||||
>Page</span
|
|
||||||
>
|
|
||||||
</h1>
|
</h1>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ Atridad Lahiji // Root
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{define "head"}}
|
{{define "head"}}
|
||||||
<link rel="stylesheet" href="/public/css/styles.home.css" />
|
<link rel="stylesheet" href="/public/css/styles.css" />
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{define "main"}}
|
{{define "main"}}
|
||||||
|
|
|
@ -7,7 +7,7 @@ Atridad Lahiji // Post
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{define "head"}}
|
{{define "head"}}
|
||||||
<link rel="stylesheet" href="/public/css/styles.post.css" />
|
<link rel="stylesheet" href="/public/css/styles.css" />
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{define "main"}}
|
{{define "main"}}
|
||||||
|
|
|
@ -7,7 +7,7 @@ Atridad Lahiji // Projects
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{define "head"}}
|
{{define "head"}}
|
||||||
<link rel="stylesheet" href="/public/css/styles.projects.css" />
|
<link rel="stylesheet" href="/public/css/styles.css" />
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{define "main"}}
|
{{define "main"}}
|
||||||
|
|
|
@ -7,7 +7,7 @@ Atridad Lahiji // Talks
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{define "head"}}
|
{{define "head"}}
|
||||||
<link rel="stylesheet" href="/public/css/styles.talks.css" />
|
<link rel="stylesheet" href="/public/css/styles.css" />
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{define "main"}}
|
{{define "main"}}
|
||||||
|
|
|
@ -7,7 +7,7 @@ Atridad Lahiji // Testimonials
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{define "head"}}
|
{{define "head"}}
|
||||||
<link rel="stylesheet" href="/public/css/styles.testimonials.css" />
|
<link rel="stylesheet" href="/public/css/styles.css" />
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{define "main"}}
|
{{define "main"}}
|
||||||
|
|
|
@ -7,7 +7,7 @@ Atridad Lahiji // Tools
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{define "head"}}
|
{{define "head"}}
|
||||||
<link rel="stylesheet" href="/public/css/styles.tools.css" />
|
<link rel="stylesheet" href="/public/css/styles.css" />
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{define "main"}}
|
{{define "main"}}
|
||||||
|
|
|
@ -7,7 +7,7 @@ Atridad Lahiji // Tools // Resizer
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{define "head"}}
|
{{define "head"}}
|
||||||
<link rel="stylesheet" href="/public/css/styles.tools.resize.css" />
|
<link rel="stylesheet" href="/public/css/styles.css" />
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{define "main"}}
|
{{define "main"}}
|
||||||
|
|
|
@ -5,7 +5,7 @@ Atridad Lahiji // Tools // SSE Demo
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{define "head"}}
|
{{define "head"}}
|
||||||
<link rel="stylesheet" href="/public/css/styles.tools.ssedemo.css" />
|
<link rel="stylesheet" href="/public/css/styles.css" />
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{define "main"}}
|
{{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