Skip to content

Commit

Permalink
feat: set custom page title
Browse files Browse the repository at this point in the history
  • Loading branch information
LifeAdventurer authored May 25, 2024
2 parents 6423ab1 + b505ccb commit 642c011
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions scripts/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ UNLOCK_PASSWORD=UNLOCK_PASSWORD
ADMIN_NAME=admin
ADMIN_MAIL=admin@admin
ADMIN_PASSWORD=admin1234
SITE_TITLE="New TNFSH Online Judge"
5 changes: 5 additions & 0 deletions scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ if [ -z $ADMIN_PASSWORD ]; then
ADMIN_PASSWORD=admin1234
fi

if [ -z $SITE_TITLE ]; then
SITE_TITLE="New TNFSH Online Judge"
fi

# Update and upgrade
sudo apt update
sudo apt upgrade
Expand Down Expand Up @@ -111,6 +115,7 @@ DBNAME_OJ = '${DB_NAME}'
DBUSER_OJ = '${DB_USERNAME}'
DBPW_OJ = '${DB_PASSWORD}'
COOKIE_SEC = '${COOKIE_SEC}'
SITE_TITLE = '${SITE_TITLE}'
lock_user_list = []
can_see_code_user = [1]
unlock_pwd = ${UNLOCK_PWD}
Expand Down
16 changes: 16 additions & 0 deletions src/utils/htmlgen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import config

def set_page_title(title: str, site_title: str = None):
if site_title is None:
site_title = config.SITE_TITLE

if title == "":
t = site_title
else:
t = f"{title} | {site_title}"

return f"""
<script>
document.title = "{t}";
</script>
"""

0 comments on commit 642c011

Please sign in to comment.