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 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
|
RUN pip3 install -r requirements.txt
|
||||||
|
|
||||||
VOLUME /wiki/src/templates/entry
|
VOLUME /wiki/templates/entry
|
||||||
|
|
||||||
EXPOSE 5000
|
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] Markdown Files (.md)
|
||||||
- [x] Entry page
|
- [x] Entry page
|
||||||
- [ ] Option to get plain text file
|
- [ ] Option to get plain text file
|
||||||
|
- [ ] Optimize CSS for code
|
||||||
|
- [x] Start page
|
||||||
- [x] Search page
|
- [x] Search page
|
||||||
- [x] Full-text search
|
- [x] Full-text search
|
||||||
- [ ] Show first few lines of each match (description)
|
- [x] Show first few lines of each match (preview)
|
||||||
|
- [ ] Better CSS
|
||||||
- [ ] Navigation
|
- [ ] Navigation
|
||||||
- [ ] More advanced namespaces
|
- [ ] More advanced namespaces
|
||||||
- [x] Header
|
- [x] Header
|
||||||
|
- [ ] Random article
|
||||||
- [ ] Search bar in header
|
- [ ] Search bar in header
|
||||||
- [x] Footer
|
- [x] Footer
|
||||||
- [x] Switchable CSS
|
- [x] Switchable CSS
|
||||||
|
1
src/.gitignore
vendored
1
src/.gitignore
vendored
@ -1,2 +1,3 @@
|
|||||||
__pycache__/
|
__pycache__/
|
||||||
indexdir/
|
indexdir/
|
||||||
|
templates/entry
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
from flask import Flask, flash, make_response, render_template, request, redirect, abort
|
from flask import Flask, flash, make_response, render_template, request, redirect, abort
|
||||||
|
|
||||||
import content as con_gen
|
import content as cont
|
||||||
import config
|
import config
|
||||||
import search as src
|
import search as src
|
||||||
from forms import SearchForm, csrf
|
from forms import SearchForm, csrf
|
||||||
@ -24,22 +24,23 @@ def page_not_found(e):
|
|||||||
@app.route('/')
|
@app.route('/')
|
||||||
@app.route('/index.html')
|
@app.route('/index.html')
|
||||||
def index():
|
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', methods=['GET', 'POST'])
|
||||||
|
@app.route('/search.html', methods=['GET', 'POST'])
|
||||||
def search():
|
def search():
|
||||||
form = SearchForm()
|
form = SearchForm()
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
query_str = request.form['query_str']
|
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=content), 200
|
||||||
return render_template('search.html', title=TITLE, style=STYLE, form=form, content=''), 200
|
return render_template('search.html', title=TITLE, style=STYLE, form=form, content=''), 200
|
||||||
|
|
||||||
|
|
||||||
@app.route('/entry/<path:fullurl>')
|
@app.route('/entry/<path:fullurl>')
|
||||||
def entry(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
|
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):
|
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
|
||||||
|
@ -8,4 +8,4 @@ csrf = CSRFProtect()
|
|||||||
class SearchForm(FlaskForm):
|
class SearchForm(FlaskForm):
|
||||||
query_str = TextField(
|
query_str = TextField(
|
||||||
"Query", [validators.Required("Please enter the search term")])
|
"Query", [validators.Required("Please enter the search term")])
|
||||||
submit = SubmitField("Send")
|
submit = SubmitField("Search")
|
||||||
|
@ -29,6 +29,16 @@ html {
|
|||||||
overflow-x: hidden;
|
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 {
|
footer {
|
||||||
height: 100px;
|
height: 100px;
|
||||||
padding-top: 20px;
|
padding-top: 20px;
|
||||||
@ -38,6 +48,10 @@ footer .center {
|
|||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ul {
|
||||||
|
padding-left: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
.container {
|
.container {
|
||||||
min-height: 100%;
|
min-height: 100%;
|
||||||
padding-bottom: 50px;
|
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.query_str }}
|
||||||
{{ form.submit }}
|
{{ form.submit }}
|
||||||
</form>
|
</form>
|
||||||
{% autoescape off %}
|
<div class="content">
|
||||||
<span>{{ content }}</span>
|
{% autoescape off %}
|
||||||
{% endautoescape %}
|
<span>{{ content }}</span>
|
||||||
|
{% endautoescape %}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user