diff --git a/README.md b/README.md index 13c6697..cf95dea 100644 --- a/README.md +++ b/README.md @@ -13,8 +13,9 @@ However I dislike using a script for adding entries and just want to add entries - [x] Archive page - [x] Months as headings - [x] Links to scrolling blog page - - [ ] Links to standalone article -- [ ] Standalone article page + - [x] Links to standalone article +- [x] Standalone article page + - [x] Links to scrolling blog page - [x] RSS feed - [ ] Better navigation - [ ] Header diff --git a/src/app.py b/src/app.py index 9a9923d..f2fb624 100644 --- a/src/app.py +++ b/src/app.py @@ -1,4 +1,4 @@ -from flask import Flask, flash, make_response, render_template, request, redirect +from flask import Flask, flash, make_response, render_template, request, redirect, abort import content as con_gen @@ -24,6 +24,13 @@ def blog_archive(): content = con_gen.gen_arch_string() return render_template('archive.html', title='Blog Archive', content_string=content) +@app.route('/entry/') +def entry(path): + content = con_gen.gen_stand_string(path) + if content != '': + return render_template('standalone.html', title='Blog Entry', content_string=content) + abort(404) + @app.route('/feed.xml') @app.route('/rss.xml') diff --git a/src/content.py b/src/content.py index 4217093..86752e3 100644 --- a/src/content.py +++ b/src/content.py @@ -36,8 +36,12 @@ def gen_arch_string(): filename = filename.split('.', 1)[0] content_string += '
  • ' content_string += curr_date + ' - ' + content_string += title + ' [' content_string += '' + title + '
    ' + filename + '">' + 'link' + ' - ' + content_string += '' + 'standalone' + '' + content_string += ']
    ' content_string += '
  • \n' content_string += '\n' return content_string @@ -60,12 +64,14 @@ def gen_index_string(): filename = filename.split('.', 1)[0] content_string += '
    \n' content_string += '

    ' + title + '

    \n' + content_string += '[' + 'standalone' + ']
    \n' if file.endswith('.html'): for line in text: content_string += line content_string += '
    ' if file.endswith('.md'): - content_string += gen_md_content(file) + content_string += gen_md_content(file, 2) content_string += '' + \ datetime.fromtimestamp(os.path.getctime( file)).strftime('%Y-%m-%d') + '' @@ -73,18 +79,40 @@ def gen_index_string(): return content_string -def gen_md_content(path_ex): +def gen_stand_string(path_ex): + filename = os.path.join(ENTRY_DIR, path_ex) + content_string = '' + if path.exists(filename): + title = open(filename).readline().rstrip('\n') + text = open(filename).readlines()[1:] + filename_no_end = filename.split('.', 1)[0] + content_string += '

    ' + title + '

    \n' + content_string += '[' + content_string += '' + 'link' + '' + content_string += ']
    \n' + if filename.endswith('.html'): + for line in text: + content_string += line + content_string += '
    ' + if filename.endswith('.md'): + content_string += gen_md_content(filename, 1) + return content_string + + +def gen_md_content(path_ex, depth): content_string = '' if path.exists(path_ex): filename = path_ex.split('.', 1) fileend = filename[len(filename) - 1] - markdown_file = open(path_ex, "r") - depth = 2 header = '#' for i in range(depth): header += '#' header += ' ' - markdown_text = markdown_file.read().replace('# ', header) + markdown_lines = open(path_ex, "r").readlines()[1:] + markdown_text = '' + for line in markdown_lines: + markdown_text += line.replace('# ', header) content_string = markdown.markdown( markdown_text, extensions=["fenced_code", "tables"] ) diff --git a/src/templates/standalone.html b/src/templates/standalone.html new file mode 100644 index 0000000..f80f5f8 --- /dev/null +++ b/src/templates/standalone.html @@ -0,0 +1,10 @@ +{% extends 'template.html' %} +{% block content %} +
    +
    + {% autoescape off %} + {{ content_string }} + {% endautoescape %} +
    +
    +{% endblock %}