fix some issues with path names

This commit is contained in:
Matthew Scragg 2015-12-09 17:41:15 -06:00
父節點 7d9cc29223
當前提交 93df0e081a
共有 4 個檔案被更改,包括 13 行新增6 行删除

查看文件

@ -5,6 +5,7 @@ reload(sys)
# noinspection PyUnresolvedReferences
sys.setdefaultencoding('utf-8')
import base64
import time
import json
import httplib
@ -185,6 +186,10 @@ def create_app(config=None):
def _jinja2_filter_datetime(ts):
return time.strftime('%b %d, %Y %I:%M %p', time.localtime(ts))
@app.template_filter('b64encode')
def _jinja2_filter_b64encode(s):
return base64.urlsafe_b64encode(s).rstrip("=")
@app.errorhandler(404)
def page_not_found(e):
return render_template('errors/404.html'), 404

查看文件

@ -83,9 +83,9 @@ def clean_url(url):
def to_canonical(s):
"""
Double space -> single dash
Double dash -> single dash
Remove all non alphanumeric and dash except path separatos (/)
Remove leading/trailing whitespace
Remove leading underscores and backslashes "/"
Convert spaces to dashes "-"
Limit to first 128 chars
"""
reserved_chars = "&$+,:;=?@#"
@ -95,7 +95,9 @@ def to_canonical(s):
s = str(s)
s = s.strip()
s = s.lstrip('_')
s = s.lstrip('/')
s = re.sub(r"\s", "-", s)
s = re.sub(r"/+", "/", s)
s = re.sub(r"[" + re.escape(reserved_chars) + "]", "", s)
s = re.sub(r"[" + re.escape(unsafe_chars) + "]", "", s)
s = s[:128]

查看文件

@ -89,13 +89,13 @@ var aced = new Aced({
info: Commit.info,
submit: function(content) {
var data = {
name: $page_name.val(),
name: $page_name.val().replace(/^\/*/g, "").replace(/\/+/g, "/"),
message: $page_message.val(),
content: content
};
// If renaming an existing page, use the old page name for the URL to PUT to
var subPath = (PAGE_NAME) ? PAGE_NAME : data['name']
var subPath = (PAGE_NAME) ? PAGE_NAME : data['name'];
var path = Config['RELATIVE_PATH'] + '/' + subPath;
var newPath = Config['RELATIVE_PATH'] + '/' + data['name'];

查看文件

@ -155,7 +155,7 @@
<a class="markdown-help" href=""><span class="hidden">What is Markdown?</span></a>
</header>
<section id="entry-markdown-content" class="entry-markdown-content">
<div id="editor-{{ name }}" data-submitbtn='submit-btn' data-themeselect="theme-list" data-mode="markdown"
<div id="editor-{{ name | b64encode }}" data-submitbtn='submit-btn' data-themeselect="theme-list" data-mode="markdown"
data-preview="preview" class="editor">{{ content }}</div>
</section>
</section>