|
|
@ -15,19 +15,19 @@ WEBSITE = config.WEBSITE
|
|
|
|
|
|
|
|
|
|
|
|
def gen_stand_string(path_ex):
|
|
|
|
def gen_stand_string(path_ex):
|
|
|
|
filename = os.path.join(ENTRY_DIR, path_ex)
|
|
|
|
filename = os.path.join(ENTRY_DIR, path_ex)
|
|
|
|
content_string = ''
|
|
|
|
result = ''
|
|
|
|
if path.exists(filename):
|
|
|
|
if path.exists(filename):
|
|
|
|
title = open(filename).readline().rstrip('\n')
|
|
|
|
title = open(filename).readline().rstrip('\n')
|
|
|
|
text = open(filename).readlines()[1:]
|
|
|
|
text = open(filename).readlines()[1:]
|
|
|
|
filename_no_end = filename.split('.', 1)[0]
|
|
|
|
filename_no_end = filename.split('.', 1)[0]
|
|
|
|
content_string += '<h1>' + title + '</h1>\n'
|
|
|
|
result += '<h1>' + title + '</h1>\n'
|
|
|
|
if filename.endswith('.md'):
|
|
|
|
if filename.endswith('.md'):
|
|
|
|
content_string += gen_md_content(filename, 1)
|
|
|
|
result += gen_md_content(filename, 1)
|
|
|
|
return content_string
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def gen_md_content(path_ex, depth):
|
|
|
|
def gen_md_content(path_ex, depth):
|
|
|
|
content_string = ''
|
|
|
|
result = ''
|
|
|
|
if path.exists(path_ex):
|
|
|
|
if path.exists(path_ex):
|
|
|
|
filename = path_ex.split('.', 1)
|
|
|
|
filename = path_ex.split('.', 1)
|
|
|
|
fileend = filename[len(filename) - 1]
|
|
|
|
fileend = filename[len(filename) - 1]
|
|
|
@ -35,14 +35,13 @@ def gen_md_content(path_ex, depth):
|
|
|
|
for i in range(depth):
|
|
|
|
for i in range(depth):
|
|
|
|
header += '#'
|
|
|
|
header += '#'
|
|
|
|
header += ' '
|
|
|
|
header += ' '
|
|
|
|
markdown_lines = open(path_ex, "r").readlines()[1:]
|
|
|
|
markdown_lines = open(path_ex, 'r').readlines()[1:]
|
|
|
|
markdown_text = ''
|
|
|
|
markdown_text = ''
|
|
|
|
for line in markdown_lines:
|
|
|
|
for line in markdown_lines:
|
|
|
|
markdown_text += line.replace('# ', header)
|
|
|
|
markdown_text += line.replace('# ', header)
|
|
|
|
content_string = markdown.markdown(
|
|
|
|
result = markdown.markdown(
|
|
|
|
markdown_text, extensions=["fenced_code", "tables"]
|
|
|
|
markdown_text, extensions=["fenced_code", "tables", "nl2br"])
|
|
|
|
)
|
|
|
|
return result
|
|
|
|
return content_string
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def gen_query_res_string(query_str):
|
|
|
|
def gen_query_res_string(query_str):
|
|
|
@ -52,7 +51,25 @@ def gen_query_res_string(query_str):
|
|
|
|
for result in src_results:
|
|
|
|
for result in src_results:
|
|
|
|
title = result['title']
|
|
|
|
title = result['title']
|
|
|
|
path = result['path']
|
|
|
|
path = result['path']
|
|
|
|
|
|
|
|
preview = create_preview(path)
|
|
|
|
path = '/entry/' + path.split('/', 2)[2]
|
|
|
|
path = '/entry/' + path.split('/', 2)[2]
|
|
|
|
res_string += '<li><a href="' + path + '">' + title + '</a></li>'
|
|
|
|
res_string += '<li><a href="' + path + '">' + title + '</a><br>'
|
|
|
|
|
|
|
|
res_string += '<div class="description">' + preview + '</div>'
|
|
|
|
|
|
|
|
res_string += '</li>'
|
|
|
|
res_string += '</ul>\n'
|
|
|
|
res_string += '</ul>\n'
|
|
|
|
return res_string
|
|
|
|
return res_string
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def create_preview(path):
|
|
|
|
|
|
|
|
file = open(path, 'r')
|
|
|
|
|
|
|
|
first_lines = file.readlines()
|
|
|
|
|
|
|
|
preview = ''
|
|
|
|
|
|
|
|
preview_length = 3
|
|
|
|
|
|
|
|
for i, line in enumerate(first_lines):
|
|
|
|
|
|
|
|
if i > preview_length:
|
|
|
|
|
|
|
|
break
|
|
|
|
|
|
|
|
if not line.isspace():
|
|
|
|
|
|
|
|
preview += line + '<br>'
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
preview_length += 1
|
|
|
|
|
|
|
|
return preview
|
|
|
|