Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2023-11-19 weekly update #9

Merged
merged 10 commits into from
Nov 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/workflows/dev_branch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Dev Branch

on:
push:
branches:
- 'dev'

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
with:
submodules: 'recursive'
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install necessary Python packages
run: |
pip install -r requirements.txt
- name: Update submodules
run: |
git submodule update --remote

# Custom script
- name: Run custom prechecking
run: python prechecker.py
29 changes: 29 additions & 0 deletions .github/workflows/pull_request.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Pull Request

on:
pull_request:
types: [opened, reopened]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
with:
submodules: 'recursive'
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install necessary Python packages
run: |
pip install -r requirements.txt
- name: Update submodules
run: |
git submodule update --remote

# Custom script
- name: Run custom prechecking
run: python prechecker.py
2 changes: 2 additions & 0 deletions .github/workflows/push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ name: Push

on:
push:
branches:
- 'main'
workflow_dispatch:
repository_dispatch:
types: [ost-data-export-update-event]
Expand Down
11 changes: 11 additions & 0 deletions _main_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
ALL_LANGS = ["en", "zh_cn"]
LANG_OTHER_PAGE = {
"page/{lang}/main_all.html": "main/index.html",
"page/{lang}/_index.html": "index.html",
"page/{lang}/_about.html": "about.html"
}
OTHER_STATIC_PAGE = {
"page/index.html": "index.html",
"page/404.html": "404.html",
"page/zh_cn/_zhcn_technical.html": "zh_cn/zhcn_technical.html"
}
13 changes: 1 addition & 12 deletions main_prod.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
from _main import *

ALL_LANGS = ["en", "zh_cn"]
LANG_OTHER_PAGE = {
"page/{lang}/main_all.html": "main/index.html",
"page/{lang}/_index.html": "index.html",
"page/{lang}/_about.html": "about.html"
}
OTHER_STATIC_PAGE = {
"page/index.html": "index.html",
"page/404.html": "404.html",
"page/zh_cn/_zhcn_technical.html": "zh_cn/zhcn_technical.html"
}
from _main_config import *

delete_old_page()
copy_static_file(True)
Expand Down
12 changes: 1 addition & 11 deletions main_test.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
from _main import *
from _main_config import *

ALL_LANGS = ["zh_cn"]
LANG_OTHER_PAGE = {
"page/{lang}/main_all.html": "main/index.html",
"page/{lang}/_index.html": "index.html",
"page/{lang}/_about.html": "about.html"
}
OTHER_STATIC_PAGE = {
"page/index.html": "index.html",
"page/404.html": "404.html",
"page/zh_cn/_zhcn_technical.html": "zh_cn/zhcn_technical.html"
}
ALL_FOLDERS = ["character"]

delete_old_page()
Expand Down
24 changes: 12 additions & 12 deletions main_tool.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import datetime
import minify_html
import time
import htmlmin
import os
import json
import urllib.parse
Expand All @@ -17,8 +17,8 @@

class JinjaTool:
@staticmethod
def get_current_utc(fmt="%Y-%m-%d %H:%M:%S"):
return datetime.datetime.utcnow().strftime(fmt)
def get_current_utc():
return time.time()

@staticmethod
def generate_tooltip_id():
Expand All @@ -31,19 +31,21 @@ def generate_tooltip_id():

@staticmethod
def js_string_safe(value):
return value.replace("&", "&").replace("'", "\'")
return (value.replace("&", "&").
replace("'", "\'").
replace("[", "[").
replace("]", "]"))

@staticmethod
def js_html_string_safe(value):
return value.replace("\n", "\\n")

@staticmethod
def page_minify_html(value):
return minify_html.minify(value, keep_closing_tags=True,
remove_processing_instructions=True). \
replace("'", "&#x27"). \
replace("</span> ", "</span>"). \
replace(" &nbsp; ", "&nbsp;")
return htmlmin.minify(value,
remove_empty_space=True,
remove_optional_attribute_quotes=False). \
replace("'", "&#x27")

@staticmethod
def get_outer_json(instance_id: str, instance_type: str):
Expand Down Expand Up @@ -154,7 +156,6 @@ def py_tooltip_background(background, instance_id, instance_type, extra_data):
# if GenerationCache.check_for_cache("all", cache_id):
# return GenerationCache.get_from_cache("all", cache_id)


for story in extra_data.values():
story = story[0]
story_parts = []
Expand Down Expand Up @@ -342,4 +343,3 @@ def py_output_usedby_story(data_story: dict, instance_uuid, instance_key):

# GenerationCache.add_to_cache("all", cache_id, [story for (i, j) in all_story_with_filetype.items() for story in j])
return all_story_with_filetype

17 changes: 8 additions & 9 deletions page/en/battle.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

{% block title %}Battle/{% if battle.filetype == 21 %}{{ battle.chapter }}-{{ battle.no[:2] }} {% endif %}{{ battle.name.en }}{% endblock title %}
{% block article_content %}
{% from "template/en/_macro.html" import get_social_for_composer %}
{% from "template/en/_macro.html" import get_social_for_composer, generate_track_anchor %}
<h1>Battle/<span>{% if battle.filetype == 21 %}{{ battle.chapter }}-{{ battle.no[:2] }}&nbsp;{% endif %}{{ battle.name.en }}</span></h1>
{% include "template/en/infobox/battle.html" %}

Expand All @@ -18,14 +18,13 @@ <h2>BOSS Info</h2>
{% endif %}

<h2 id="track">Track Info</h2>
{% if battle.filetype in [21, 22] %}
{% set track = battle.track.0 %}
{% else %}
{% set track = battle.track %}
{% endif %}
<ul>
<li>Track: <a href="/en/track/{{ track.namespace.1 }}/{{ track.no }}.html#{{ battle.uuid }}">{{ track.no }}. {{ track.name.realname.en }}</a></li>
<li>Description: {{ track.desc.en }}</li>
<li>Composer: {{ track.composer.nickname }} ({{ get_social_for_composer(track.composer) }})</li>
{% if battle.track|is_list %}
{% for i in battle.track %}
<li>{{ generate_track_anchor(i, 0, 0, 0, 0, True) }}</li>
{% endfor %}
{% else %}
<li>{{ generate_track_anchor(battle.track, 0, 0, 0, 0, True) }}</li>
{% endif %}
</ul>
{% endblock %}
2 changes: 1 addition & 1 deletion page/en/character_all.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ <h2>Students</h2>
{% set curr = i.1 %}
<li>
<a href="/en/character/student/{{ curr.student.name.path_name|lower }}/">
<img src="{{ get_static('images/student/icon/{{ curr.student.image.collection_texture }}.webp') }}" class="icon-stu"/>{{ curr.student.name.name.en }}<span lang="jp" class="char-lang-jp">&nbsp;/&nbsp;{{ curr.student.name.name.jp }}</span>
<img src="{{ get_static('images/student/icon/' + curr.student.image.collection_texture + '.webp') }}" class="icon-stu"/>{{ curr.student.name.name.en }}<span lang="jp" class="char-lang-jp">&nbsp;/&nbsp;{{ curr.student.name.name.jp }}</span>
</a>
<br/>
<div class="stu-list-desc">
Expand Down
3 changes: 2 additions & 1 deletion page/en/video.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{% extends "template/en/base.html" %}
{% from 'template/en/_macro.html' import output_video_stat_badge %}
{% from 'template/en/_macro_page.html' import output_usedby_track_list, track_version_video_player %}

{% block title %}Video/{{ video.name.en }}{% endblock title %}
{% block other_head %}
<script src="{{ get_static('js/track_player.js') }}"></script>
{% endblock other_head %}
{% block article_content %}
<h1>Video/{{ video.name.en }}</h1>
<h1>Video/{{ video.name.en }} {{ output_video_stat_badge(video.stats) }}</h1>
{% include "template/en/infobox/video.html" %}
<p><b>{{ video.name.en }}</b> is a video related to Blue Archive.</p>
<h2>Track Information</h2>
Expand Down
5 changes: 4 additions & 1 deletion page/en/video_all.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% extends "template/en/base.html" %}
{% from 'template/en/_macro.html' import output_video_stat_badge %}

{% block title %}{{ video.name.en }}{% endblock title %}
{% block article_content %}
Expand All @@ -7,7 +8,9 @@ <h1>{{ video.name.en }}</h1>
<ul>
{% for i in video.include %}
{% set i = i[1] %}
<li><a href="/en/video/{{ i.namespace.1 }}.html">{{ i.name.en }}</a>&nbsp;-&nbsp;{{ i.desc.en }}</li>
<li><a href="/en/video/{{ i.namespace.1 }}.html">{{ i.name.en }}</a> {{ output_video_stat_badge(i.stats) }}
<br />{{ i.desc.en }}
</li>
{% endfor %}
</ul>
{% endblock article_content %}
17 changes: 8 additions & 9 deletions page/zh_cn/battle.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

{% block title %}任务/{% if battle.filetype == 21 %}{{ battle.chapter }}-{{ battle.no[:2] }} {% endif %}{{ battle.name.zh_cn }}{% endblock title %}
{% block article_content %}
{% from "template/zh_cn/_macro.html" import get_social_for_composer, auto_zhcn_gen %}
{% from "template/zh_cn/_macro.html" import get_social_for_composer, auto_zhcn_gen, generate_track_anchor %}
<h1>战斗/<span>{% if battle.filetype == 21 %}{{ battle.chapter }}-{{ battle.no[:2] }}&nbsp;{% endif %}{{ auto_zhcn_gen(battle.name) }}</span></h1>
{% include "template/zh_cn/infobox/battle.html" %}

Expand All @@ -18,14 +18,13 @@ <h2>BOSS信息</h2>
{% endif %}

<h2 id="track">曲目信息</h2>
{% if battle.filetype in [21, 22] %}
{% set track = battle.track.0 %}
{% else %}
{% set track = battle.track %}
{% endif %}
<ul>
<li>曲子:<a href="/zh_cn/track/{{ track.namespace.1 }}/{{ track.no }}.html#{{ battle.uuid }}">{{ track.no }}. {{ track.name.realname.en }} {% if track.name.realname.zh_cn %}({{ track.name.realname.zh_cn }}){% endif %}</a></li>
<li>简介:{{ track.desc.zh_cn }}</li>
<li>作曲家:{{ track.composer.nickname }} ({{ get_social_for_composer(track.composer) }})</li>
{% if battle.track|is_list %}
{% for i in battle.track %}
<li>{{ generate_track_anchor(i, 0, 0, 0, 0, True) }}</li>
{% endfor %}
{% else %}
<li>{{ generate_track_anchor(battle.track, 0, 0, 0, 0, True) }}</li>
{% endif %}
</ul>
{% endblock article_content %}
3 changes: 2 additions & 1 deletion page/zh_cn/video.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{% extends "template/zh_cn/base.html" %}
{% from 'template/zh_cn/_macro.html' import output_video_stat_badge %}
{% from 'template/zh_cn/_macro_page.html' import output_usedby_track_list, track_version_video_player %}

{% block title %}视频/{{ video.name.zh_cn }}{% endblock title %}
{% block title %}视频/{{ video.name.zh_cn }} {{ output_video_stat_badge(video.stats) }}{% endblock title %}
{% block other_head %}
<script src="{{ get_static('js/track_player.js') }}"></script>
{% endblock other_head %}
Expand Down
5 changes: 4 additions & 1 deletion page/zh_cn/video_all.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% extends "template/zh_cn/base.html" %}
{% from 'template/zh_cn/_macro.html' import output_video_stat_badge %}

{% block title %}{{ video.name.zh_cn }}{% endblock title %}
{% block article_content %}
Expand All @@ -7,7 +8,9 @@ <h1>{{ video.name.zh_cn }}</h1>
<ul>
{% for i in video.include %}
{% set i = i[1] %}
<li><a href="/zh_cn/video/{{ i.namespace.1 }}.html">{{ i.name.zh_cn }}</a>&nbsp;-&nbsp;{{ i.desc.zh_cn }}</li>
<li><a href="/zh_cn/video/{{ i.namespace.1 }}.html">{{ i.name.zh_cn }}</a> {{ output_video_stat_badge(i.stats) }}
<br />{{ i.desc.zh_cn }}
</li>
{% endfor %}
</ul>
{% endblock article_content %}
49 changes: 49 additions & 0 deletions precheck_script/check_static.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import time

ALL_LANGS = ["en", "zh_cn"]


def render_template(env, path):
print(f"[INFO]\tTesting {path}...")
try:
template = env.get_template(path)

start = time.time_ns()
template.render(is_static=True)
end = time.time_ns()
except Exception as e:
print(f"[FAIL]\tFailed with exception: {str(e)}")
raise e
else:
print(f"[OK]\tSuccessfully tested (runtime {(end - start) / 1e6} ms)")


def check_static_per_lang(env, page: dict):
total = len(page.keys())
failed_count = 0

for i in ALL_LANGS:
for path, name in page.items():
try:
render_template(env, path.format(lang=i))
except Exception:
failed_count += 1

print(f"Total {total}, failed {failed_count} ({failed_count / total * 100:0.2f}%)")
if failed_count != 0:
raise AssertionError


def check_static_otehr(env, page: dict):
total = len(page.keys())
failed_count = 0

for path, name in page.items():
try:
render_template(env, path)
except Exception:
failed_count += 1

print(f"Total {total}, failed {failed_count} ({failed_count / total * 100:0.2f}%)")
if failed_count != 0:
raise AssertionError
Loading
Loading