mirror of
https://github.com/tiyn/amphora-wiki.git
synced 2025-04-19 15:27:46 +02:00
search: preview added
- The search result list now has previews - The Dockerfile doesnt need git anymore
This commit is contained in:
parent
19cf415947
commit
26ecbf1007
@ -4,15 +4,15 @@ MAINTAINER Tiyn tiyn@martenkante.eu
|
||||
|
||||
RUN apt-get update
|
||||
|
||||
RUN apt-get install python3 python3-pip git -y
|
||||
RUN apt-get install python3 python3-pip -y
|
||||
|
||||
RUN git clone https://github.com/tiyn/tiyny-wiki /wiki
|
||||
COPY src /wiki
|
||||
|
||||
WORKDIR /wiki/src
|
||||
WORKDIR /wiki
|
||||
|
||||
RUN pip3 install -r requirements.txt
|
||||
|
||||
VOLUME /wiki/src/templates/entry
|
||||
VOLUME /wiki/templates/entry
|
||||
|
||||
EXPOSE 5000
|
||||
|
@ -11,12 +11,16 @@ I however just want to put my markdown files in a directory and get a working wi
|
||||
- [x] Markdown Files (.md)
|
||||
- [x] Entry page
|
||||
- [ ] Option to get plain text file
|
||||
- [ ] Optimize CSS for code
|
||||
- [x] Start page
|
||||
- [x] Search page
|
||||
- [x] Full-text search
|
||||
- [ ] Show first few lines of each match (description)
|
||||
- [x] Show first few lines of each match (preview)
|
||||
- [ ] Better CSS
|
||||
- [ ] Navigation
|
||||
- [ ] More advanced namespaces
|
||||
- [x] Header
|
||||
- [ ] Random article
|
||||
- [ ] Search bar in header
|
||||
- [x] Footer
|
||||
- [x] Switchable CSS
|
||||
|
1
src/.gitignore
vendored
1
src/.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
__pycache__/
|
||||
indexdir/
|
||||
templates/entry
|
||||
|
@ -1,7 +1,7 @@
|
||||
import os
|
||||
from flask import Flask, flash, make_response, render_template, request, redirect, abort
|
||||
|
||||
import content as con_gen
|
||||
import content as cont
|
||||
import config
|
||||
import search as src
|
||||
from forms import SearchForm, csrf
|
||||
@ -24,22 +24,23 @@ def page_not_found(e):
|
||||
@app.route('/')
|
||||
@app.route('/index.html')
|
||||
def index():
|
||||
return 'placeholder for index', 200
|
||||
return render_template('index.html', title=TITLE, style=STYLE), 200
|
||||
|
||||
|
||||
@app.route('/search', methods=['GET', 'POST'])
|
||||
@app.route('/search.html', methods=['GET', 'POST'])
|
||||
def search():
|
||||
form = SearchForm()
|
||||
if request.method == 'POST':
|
||||
query_str = request.form['query_str']
|
||||
content = con_gen.gen_query_res_string(query_str)
|
||||
content = cont.gen_query_res_string(query_str)
|
||||
return render_template('search.html', title=TITLE, style=STYLE, form=form, content=content), 200
|
||||
return render_template('search.html', title=TITLE, style=STYLE, form=form, content=''), 200
|
||||
|
||||
|
||||
@app.route('/entry/<path:fullurl>')
|
||||
def entry(fullurl):
|
||||
content = con_gen.gen_stand_string(fullurl)
|
||||
content = cont.gen_stand_string(fullurl)
|
||||
return render_template('entry.html', title=TITLE, style=STYLE, content=content), 200
|
||||
|
||||
|
||||
|
@ -15,19 +15,19 @@ WEBSITE = config.WEBSITE
|
||||
|
||||
def gen_stand_string(path_ex):
|
||||
filename = os.path.join(ENTRY_DIR, path_ex)
|
||||
content_string = ''
|
||||
result = ''
|
||||
if path.exists(filename):
|
||||
title = open(filename).readline().rstrip('\n')
|
||||
text = open(filename).readlines()[1:]
|
||||
filename_no_end = filename.split('.', 1)[0]
|
||||
content_string += '<h1>' + title + '</h1>\n'
|
||||
result += '<h1>' + title + '</h1>\n'
|
||||
if filename.endswith('.md'):
|
||||
content_string += gen_md_content(filename, 1)
|
||||
return content_string
|
||||
result += gen_md_content(filename, 1)
|
||||
return result
|
||||
|
||||
|
||||
def gen_md_content(path_ex, depth):
|
||||
content_string = ''
|
||||
result = ''
|
||||
if path.exists(path_ex):
|
||||
filename = path_ex.split('.', 1)
|
||||
fileend = filename[len(filename) - 1]
|
||||
@ -35,14 +35,13 @@ def gen_md_content(path_ex, depth):
|
||||
for i in range(depth):
|
||||
header += '#'
|
||||
header += ' '
|
||||
markdown_lines = open(path_ex, "r").readlines()[1:]
|
||||
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"]
|
||||
)
|
||||
return content_string
|
||||
result = markdown.markdown(
|
||||
markdown_text, extensions=["fenced_code", "tables", "nl2br"])
|
||||
return result
|
||||
|
||||
|
||||
def gen_query_res_string(query_str):
|
||||
@ -52,7 +51,25 @@ def gen_query_res_string(query_str):
|
||||
for result in src_results:
|
||||
title = result['title']
|
||||
path = result['path']
|
||||
preview = create_preview(path)
|
||||
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'
|
||||
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
|
||||
|
@ -8,4 +8,4 @@ csrf = CSRFProtect()
|
||||
class SearchForm(FlaskForm):
|
||||
query_str = TextField(
|
||||
"Query", [validators.Required("Please enter the search term")])
|
||||
submit = SubmitField("Send")
|
||||
submit = SubmitField("Search")
|
||||
|
@ -29,6 +29,16 @@ html {
|
||||
overflow-x: hidden;
|
||||
}
|
||||
|
||||
code {
|
||||
border-radius: 25px;
|
||||
padding-left: 20px;
|
||||
padding-right: 20px;
|
||||
page-break-inside: avoid;
|
||||
font-family: monospace;
|
||||
white-space: pre;
|
||||
display: inline-block
|
||||
}
|
||||
|
||||
footer {
|
||||
height: 100px;
|
||||
padding-top: 20px;
|
||||
@ -38,6 +48,10 @@ footer .center {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
ul {
|
||||
padding-left: 10px;
|
||||
}
|
||||
|
||||
.container {
|
||||
min-height: 100%;
|
||||
padding-bottom: 50px;
|
||||
|
9
src/templates/index.html
Normal file
9
src/templates/index.html
Normal file
@ -0,0 +1,9 @@
|
||||
{% extends "template.html" %}
|
||||
{% block content %}
|
||||
<div class="container">
|
||||
<div class="important">
|
||||
This is the<br>
|
||||
<span>{{ title }}</span>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
@ -7,9 +7,11 @@
|
||||
{{ form.query_str }}
|
||||
{{ form.submit }}
|
||||
</form>
|
||||
{% autoescape off %}
|
||||
<span>{{ content }}</span>
|
||||
{% endautoescape %}
|
||||
<div class="content">
|
||||
{% autoescape off %}
|
||||
<span>{{ content }}</span>
|
||||
{% endautoescape %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
Loading…
x
Reference in New Issue
Block a user