version bootstrap-style.css and add version_css to build.sh
This commit is contained in:
parent
0c58cea663
commit
bd3f58929a
2 changed files with 54 additions and 3 deletions
|
@ -11,12 +11,12 @@
|
|||
{{ end -}}
|
||||
<title>{{ title }}</title>
|
||||
|
||||
<link href="/img/favicon.png" rel="icon" />
|
||||
{* TODO: figure out custom themes (e.g. charcoal theme) *}
|
||||
<link href="/css/bootstrap-style.css?hash=19fd3683" rel="stylesheet" fetchpriority="high" integrity="sha256-Gf02g6a37bUHEI24c38q3OgrYA8d7RG4I6unZ7e62Pc=" />
|
||||
|
||||
<link rel="stylesheet" href="/css/bootstrap-icons-1.11.3/bootstrap-icons.min.css" />
|
||||
|
||||
{* TODO: figure out custom themes (e.g. charcoal theme) *}
|
||||
<link href="/css/bootstrap-style.css" rel="stylesheet" />
|
||||
<link href="/img/favicon.png" rel="icon" />
|
||||
|
||||
<script src="/js/htmx@1.9.10.min.js" integrity="sha384-D1Kt99CQMDuVetoL1lrYwg5t+9QdHe7NLX/SoJYkXDFfX37iInKRy5xLSi8nO7UC"></script>
|
||||
<!-- <script src="/js/idiomorph@0.3.0.js"></script> -->
|
||||
|
|
51
build.sh
51
build.sh
|
@ -37,6 +37,7 @@ build() {
|
|||
echo "jq and semgrep found. "
|
||||
i18n
|
||||
fi
|
||||
version_css
|
||||
CGO_ENABLED=0 go build -v -ldflags="-extldflags=-static -X codeberg.org/vnpower/pixivfe/v2/config.revision=${REVISION}" -o "${BINARY_NAME}"
|
||||
}
|
||||
|
||||
|
@ -46,6 +47,54 @@ build_docker() {
|
|||
CGO_ENABLED=0 go build -v -ldflags="-extldflags=-static -X codeberg.org/vnpower/pixivfe/v2/config.revision=${REVISION}" -o "${BINARY_NAME}"
|
||||
}
|
||||
|
||||
version_css() {
|
||||
CSS_FILE="./assets/css/bootstrap-style.css"
|
||||
HTML_FILE="./assets/views/layout/default.jet.html"
|
||||
|
||||
echo "Computing SHA256 checksum for ${CSS_FILE}..."
|
||||
|
||||
if [ ! -f "${CSS_FILE}" ]; then
|
||||
echo "Error: ${CSS_FILE} does not exist."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Compute checksum and truncate to first 8 characters for the href query parameter
|
||||
checksum=$(sha256sum "${CSS_FILE}" | awk '{print $1}' | cut -c1-8)
|
||||
echo "Truncated SHA256 checksum for ${CSS_FILE}: ${checksum}"
|
||||
|
||||
# Compute the SRI hash for the integrity attribute
|
||||
echo "Computing SRI hash for ${CSS_FILE}..."
|
||||
# SRI_HASH=$(openssl dgst -sha256 -binary "${CSS_FILE}" | openssl base64 -A)
|
||||
SRI_HASH=$(sha256sum "${CSS_FILE}" | awk '{print $1}' | xxd -r -p | base64 -w 0)
|
||||
echo "Computed SRI hash: sha256-${SRI_HASH}"
|
||||
|
||||
echo "Updating ${HTML_FILE} with the truncated checksum and SRI hash..."
|
||||
|
||||
if [ ! -f "${HTML_FILE}" ]; then
|
||||
echo "Error: ${HTML_FILE} does not exist."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Create a backup before modifying
|
||||
cp "${HTML_FILE}" "${HTML_FILE}.bak"
|
||||
|
||||
# Replace the href attribute's query parameter with the new truncated hash
|
||||
sed -i -E 's|(href="/css/bootstrap-style\.css)[^"]*(" [^>]*>)|\1?hash='"${checksum}"'\2|' "${HTML_FILE}"
|
||||
|
||||
# Replace the integrity attribute with the new SRI hash
|
||||
sed -i -E 's|(href="/css/bootstrap-style\.css[^"]*"[^>]*integrity=")[^"]*(")|\1sha256-'"${SRI_HASH}"'\2|' "${HTML_FILE}"
|
||||
|
||||
# Check if sed was successful
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "Successfully updated ${HTML_FILE} with the new truncated hash and SRI hash."
|
||||
rm "${HTML_FILE}.bak"
|
||||
else
|
||||
echo "Failed to update ${HTML_FILE}. Restoring from backup."
|
||||
mv "${HTML_FILE}.bak" "${HTML_FILE}"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
test() {
|
||||
echo "Running tests..."
|
||||
go test ./...
|
||||
|
@ -123,6 +172,7 @@ help() {
|
|||
echo " build - Build the binary"
|
||||
echo " build_docker - Build the binary (for Docker, skips i18n refresh)"
|
||||
echo " scan - Scan Go code"
|
||||
echo " version_css - Compute SHA256 checksum for bootstrap-style.css and update HTML"
|
||||
echo " test - Run tests"
|
||||
echo " i18n - Extract i18n strings"
|
||||
echo " i18n-up - Upload strings to Crowdin"
|
||||
|
@ -148,6 +198,7 @@ execute_command() {
|
|||
fmt) fmt ;;
|
||||
build) build ;;
|
||||
build_docker) build_docker ;;
|
||||
version_css) version_css ;;
|
||||
test) test ;;
|
||||
scan) scan ;;
|
||||
i18n) i18n ;;
|
||||
|
|
Loading…
Reference in a new issue