From 3bef8e7ae94e98bcf8be5273ae6ffa2d525af11c Mon Sep 17 00:00:00 2001 From: chenmo Date: Mon, 1 Apr 2024 19:16:39 +0100 Subject: [PATCH] fix: the desc gap of sharing post --- app.py | 14 +++++++------- index.html | 6 ++++-- static/js/common.js | 4 ++-- static/js/main.js | 3 ++- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/app.py b/app.py index 796b687..2ae3390 100644 --- a/app.py +++ b/app.py @@ -7,27 +7,27 @@ app = Flask(__name__) -# 定义文章存储的目录 +# Define the directory where articles are stored ARTICLES_DIR = 'articles' def clean_filename(filename): - # Windows文件名不允许的字符 + # Characters not allowed in Windows file names invalid_chars = r'<>:"/\|?*' for char in invalid_chars: filename = filename.replace(char, '') - # 进一步去除非打印字符等其他可能的问题字符 + # Further remove non-printing characters and other possible problem characters filename = re.sub(r'[^.\w\s-]', '', filename) - # 去除两边的空格,并确保文件名不为空 + # Remove spaces from both sides and make sure the filename is not empty filename = filename.strip() - # 如果文件名为空(或者只包含了非法字符),提供一个默认值 + # If the file name is empty (or contains only illegal characters), provide a default value if not filename: filename = "default_filename" return filename def load_random_article(articles_dir): - # 获取所有json文件 + # Get all json files json_files = [f for f in os.listdir(articles_dir) if f.endswith('.json')] if not json_files: return None @@ -71,7 +71,7 @@ def article(article_id): if article: return render_template('index.html', **article) else: - abort(404) # 如果文章不存在,返回404错误 + abort(404) # If the article does not exist, a 404 error is returned if __name__ == '__main__': diff --git a/index.html b/index.html index 72fcac0..739f01f 100644 --- a/index.html +++ b/index.html @@ -113,8 +113,10 @@
- - + + + + diff --git a/static/js/common.js b/static/js/common.js index 20e22e1..84f06f9 100644 --- a/static/js/common.js +++ b/static/js/common.js @@ -6,7 +6,7 @@ function my$(id) { // 页面加载完以后加载字体文件 window.onload = function () { let xhr = new XMLHttpRequest(); // 定义一个异步对象 - xhr.open('GET', '/static/fonts/text.ttf', true); // 异步GET方式加载字体 + xhr.open('GET', 'https://cdn.chenmo1212.cn/files/font/text.ttf', true); // 异步GET方式加载字体 xhr.responseType = "arraybuffer"; //把异步获取类型改为arraybuffer二进制类型 xhr.onload = function () { // 这里做了一个判断:如果浏览器支持FontFace方法执行 @@ -17,7 +17,7 @@ window.onload = function () { // } else { // 如果浏览器不支持FontFace方法,直接添加样式到页面 let styles = document.createElement('style'); - styles.innerHTML = '@font-face{font-family:"text";src:url("/static/fonts/text.ttf") format("truetype");font-display:swap;}'; + styles.innerHTML = '@font-face{font-family:"text";src:url("https://cdn.chenmo1212.cn/files/font/text.ttf") format("truetype");font-display:swap;}'; console.log(document.getElementsByTagName('head')); document.getElementsByTagName('head')[0].appendChild(styles); // } diff --git a/static/js/main.js b/static/js/main.js index c388bcd..977d616 100644 --- a/static/js/main.js +++ b/static/js/main.js @@ -147,7 +147,6 @@ function setBookmark(type) { */ function toGetSharePost() { - // 显示loading loadingContainer.style.display = 'block' const sharingUrl = `http://${window.location.host}/article/${title}`; @@ -157,6 +156,8 @@ function toGetSharePost() { title_.innerText = title.innerHTML author_.innerText = author.innerHTML + // Remove P label + desc_.innerHTML = content.innerHTML.replace(/]*>(.*?)<\/p>/gi, "$1"); my$('sharing').style.display = 'block' splitContent(content.innerHTML, desc_, 2, 5);