Преглед на файлове

210809 fixes
translation limit
img filename
description newline

yukyo0821 преди 3 години
родител
ревизия
af86ea69a0

+ 1 - 1
backstage/collections/routes.py

@@ -53,7 +53,7 @@ description: "{}"\n\
               'collection',
               '/collection/{}'.format(eng_name),
               form.image.data.filename,
-              form.description.data)
+              form.description.data.replace('\r\n','<br>'))
     data = {'frontMatter': front_matter,
             'name': eng_name,
             'type': 'collection'}

+ 2 - 1
backstage/static/js/editor.js

@@ -169,6 +169,7 @@ submitButton.onclick = function () {
       mdContent += frontMatter + '\n';
     }
     */
+    //alert($('#cdescription').val());
     mdContent += '---\n';
     mdContent += 'title: "' + $('#ctitle').val() + '"\n';
     mdContent += 'date: ' + $('#cdate').val() + '\n';
@@ -176,7 +177,7 @@ submitButton.onclick = function () {
     mdContent += 'type: "' + $('#ctype').val() + '"\n';
     mdContent += 'url: "' + $('#curl').val() + '"\n';
     mdContent += 'image: "' + $('#cimage').val() + '"\n';
-    mdContent += 'description: "' + $('#cdescription').val() + '"\n';
+    mdContent += 'description: "' + $('#cdescription').val().replace(/\r?\n/g,'<br>') + '"\n';
     mdContent += 'weight: ' + ($('#cweight').val() == 'undefined' ? "" : $('#cweight').val()) + '\n';
     mdContent += 'tag: "' + ($('#ctag').val() == 'undefined' ? "" : $('#ctag').val()) + '"\n';
     mdContent += '---\n\n';

+ 1 - 1
backstage/static/js/yo.js

@@ -54,7 +54,7 @@ function parseMd(content) {
             }
             if (line.includes('description: ')) {
                 //alert(line);
-                $('#cdescription').val(line.replace('description: ', '').replaceAll('\"', ''));
+                $('#cdescription').val(line.replace('description: ', '').replaceAll('\"', '').replaceAll('<br>', '\r\n'));
             }
             if (line.includes('weight: ')) {
                 //alert(line);

+ 1 - 1
backstage/templates/tables/editor_table.html

@@ -164,7 +164,7 @@
     mdContent += 'url: "' + $('#curl').val() + '"\n';
     //mdContent += 'url: "' + $('#curl').val() + '"\n';
     mdContent += 'image: "' + $('#cimage').val() + '"\n';
-    mdContent += 'description: "' + $('#cdescription').val() + '"\n';
+    mdContent += 'description: "' + $('#cdescription').val().replace(/\r?\n/g,'<br>') + '"\n';
     mdContent += 'weight: ' + ($('#cweight').val() == 'undefined' ? "" : $('#cweight').val()) + '\n';
     mdContent += 'tag: "' + ($('#ctag').val() == 'undefined' ? "" : $('#ctag').val()) + '"\n';
     mdContent += '---\n';

+ 5 - 3
backstage/utils/__init__.py

@@ -1,13 +1,15 @@
 # coding:utf-8
-from translate import Translator
+#from translate import Translator
 #from googletrans import Translator
+from deep_translator import GoogleTranslator
 from datetime import datetime, timezone, timedelta
 
 
 def translate(text):
     #result = Translator().translate(text, dest='en')
-    translator= Translator(from_lang="zh-tw",to_lang="en")
-    result = translator.translate(text)
+    result = GoogleTranslator(source='zh-tw', target='en').translate(text)
+    #translator= Translator(from_lang="zh-tw",to_lang="en")
+    #result = translator.translate(text)
     return str(result).lower()
 
 

+ 1 - 1
backstage/utils/routes.py

@@ -37,7 +37,7 @@ def remove_content():
 
 
 def get_trans_title_url_name(title):
-    tary = translate(title).replace('$','_').replace('&','_').replace('+','_').replace(',','_').replace('/','_').replace(':','_').replace(';','_').replace('=','_').replace('?','_').replace('@','_').replace(' ','_').split('_')
+    tary = translate(title).replace('$','_').replace('&','_').replace('+','_').replace(',','_').replace('/','_').replace(':','_').replace(';','_').replace('=','_').replace('?','_').replace('@','_').replace(' ','_').replace("'",'_').split('_')
     while("" in tary) :
         tary.remove("")
     return ('_'.join(tary))