Skip to content

Commit

Permalink
fix: the desc gap of sharing post
Browse files Browse the repository at this point in the history
  • Loading branch information
Chenmo1212 committed Apr 1, 2024
1 parent 9c9a403 commit 3bef8e7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
14 changes: 7 additions & 7 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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__':
Expand Down
6 changes: 4 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,10 @@
<div class="mode" id="darkMode"></div>
</div>
<link rel="stylesheet" href="dist/css/animate.css">
<script src="dist/js/plugins/html2canvas.js"></script>
<script src="dist/js/plugins/qrcode.min.js"></script>
<!--<script src="dist/js/plugins/html2canvas.js"></script>-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.4.1/html2canvas.min.js"></script>
<!--<script src="dist/js/plugins/qrcode.min.js"></script>-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/qrcodejs/1.0.0/qrcode.min.js"></script>
<script src="dist/js/common.js?v=0.82"></script>
<script src="./dist/toast/toast.js"></script>
<script src="dist/js/main.js?v=0.84"></script>
Expand Down
4 changes: 2 additions & 2 deletions static/js/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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方法执行
Expand All @@ -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);
// }
Expand Down
3 changes: 2 additions & 1 deletion static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ function setBookmark(type) {
*/

function toGetSharePost() {
// 显示loading
loadingContainer.style.display = 'block'

const sharingUrl = `http://${window.location.host}/article/${title}`;
Expand All @@ -157,6 +156,8 @@ function toGetSharePost() {

title_.innerText = title.innerHTML
author_.innerText = author.innerHTML
// Remove P label
desc_.innerHTML = content.innerHTML.replace(/<p[^>]*>(.*?)<\/p>/gi, "$1");

my$('sharing').style.display = 'block'
splitContent(content.innerHTML, desc_, 2, 5);
Expand Down

0 comments on commit 3bef8e7

Please sign in to comment.