Skip to content

Commit 816b2ad

Browse files
committed
feat: add version display functionality with CSS styling and update script
1 parent ff8ee25 commit 816b2ad

3 files changed

Lines changed: 84 additions & 0 deletions

File tree

static/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<div class="header-top">
1515
<h1 id="mainTitle">RoadbookMaker</h1>
1616
<div id="onlineModeActions" class="online-mode-actions"></div>
17+
<span id="version-display"></span>
1718
<div class="theme-toggle-container">
1819
<button id="themeToggleBtn" class="theme-toggle-btn" title="切换主题">
1920
<span id="themeIcon">☀️</span>

static/style.css

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2813,3 +2813,24 @@ body.dark-mode .leaflet-tile {
28132813
text-decoration: underline;
28142814
}
28152815

2816+
#version-display {
2817+
display: none;
2818+
position: absolute;
2819+
top: 50%;
2820+
transform: translateY(-50%);
2821+
z-index: 1001;
2822+
right: 170px; /* Calculated: 90px (theme btn right) + 10px (gap) + ~70px (avg version width) */
2823+
}
2824+
2825+
#version-display.version-visible {
2826+
display: inline-block;
2827+
font-size: 0.7rem;
2828+
font-weight: 400;
2829+
padding: 0.1rem 0.5rem;
2830+
background-color: rgba(255,255,255,0.2);
2831+
color: white;
2832+
border-radius: 8px;
2833+
vertical-align: middle;
2834+
}
2835+
2836+

update_version.sh

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/bin/bash
2+
3+
INDEX_FILE="static/index.html"
4+
ORIGINAL_SPAN='<span id="version-display"></span>'
5+
6+
# Function to display help message
7+
display_help() {
8+
echo "Usage: $0 [OPTION]"
9+
echo ""
10+
echo "Update the version string in index.html with the current Git commit hash or tag."
11+
echo ""
12+
echo "Options:"
13+
echo " reset Revert index.html to its original state (no version displayed)."
14+
echo " -h, --help Display this help message."
15+
echo ""
16+
echo "If no option is provided, the script will update the version string."
17+
exit 0
18+
}
19+
20+
# Argument parsing
21+
if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
22+
display_help
23+
fi
24+
25+
# Reset mode: if the first argument is 'reset', revert the span to its original state
26+
if [ "$1" == "reset" ]; then
27+
# This sed command finds the version span (regardless of its content or class)
28+
# and replaces it with the original, empty, class-less span.
29+
# Using '#' as a delimiter to avoid issues with '/' or '>' in HTML tags
30+
sed -i -E 's#<span id="version-display"[^>]*>.*</span>#<span id="version-display"></span>#g' "$INDEX_FILE"
31+
echo "Version display has been reset in $INDEX_FILE"
32+
exit 0
33+
fi
34+
35+
# Default mode: Update version
36+
# Get the git version string using describe for a more readable version
37+
GIT_VERSION=$(git describe --tags --always)
38+
if [ -z "$GIT_VERSION" ]; then
39+
echo "Error: Not a git repository or no commits yet."
40+
exit 1
41+
fi
42+
43+
# The version string is the git version itself, no 'v' prefix needed here
44+
VERSION_STRING="$GIT_VERSION"
45+
46+
# Check if the index file exists
47+
if [ ! -f "$INDEX_FILE" ]; then
48+
echo "Error: $INDEX_FILE not found."
49+
exit 1
50+
fi
51+
52+
# Use sed to update the version and add the visibility class.
53+
# This works by finding the empty version-display span and replacing its outer HTML
54+
# with the version string and the class attribute.
55+
sed -i -E 's#<span id="version-display"></span>#<span id="version-display" class="version-visible">'${VERSION_STRING}'</span>#g' "$INDEX_FILE"
56+
57+
echo "Successfully updated version in $INDEX_FILE to $VERSION_STRING"
58+
59+
# A small check to see if it worked.
60+
if ! grep -q "version-visible" "$INDEX_FILE"; then
61+
echo "Warning: Failed to make version visible. The span tag might not have been found correctly."
62+
fi

0 commit comments

Comments
 (0)