Skip to content

Commit

Permalink
FIX: issue with backlink rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
Uzay-G committed Mar 23, 2021
1 parent c34f7a0 commit bbe836c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
5 changes: 3 additions & 2 deletions archivy/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,19 @@ def show_dataobj(dataobj_id):
if request.args.get("raw") == "1":
return frontmatter.dumps(dataobj)

backlinks = []
if app.config["SEARCH_CONF"]["enabled"]:
incoming_links = search(f"/{dataobj_id}\)]]")
if incoming_links:
dataobj.content += "\n# Backlinks"
for hit in incoming_links:
if hit["id"] != dataobj_id:
dataobj.content += f"\n- [{hit['title']}](/dataobj/{hit['id']})"
backlinks.append({"title": hit["title"], "id": hit["id"]})

return render_template(
"dataobjs/show.html",
title=dataobj["title"],
dataobj=dataobj,
backlinks=backlinks,
current_path=dataobj["dir"],
form=forms.DeleteDataForm(),
view_only=0,
Expand Down
34 changes: 28 additions & 6 deletions archivy/templates/dataobjs/show.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ <h2 id="post-title">{{ dataobj['title'] }}</h2>
<textarea id="original-textarea" aria-label="Text editor">
</textarea>
{% endif %}

{% if backlinks %}
<ul id="backlinks">
<h3>Backlinks</h3>
{% for backlink in backlinks %}
<li><a href="/dataobj/{{ backlink['id'] }}">{{ backlink["title"] }}</a></li>
{% endfor %}
</ul>
{% endif %}
</div>
{% if not view_only %}
<button class="sr-only" type="button" id="sr-savebutton">Save</button>
Expand All @@ -67,9 +76,15 @@ <h2 id="post-title">{{ dataobj['title'] }}</h2>
| safe
%} */

document.getElementById("content").innerHTML = window.parser.render(`\${toc}\n{{ content }}`)

let contentDiv = document.getElementById("content");
function renderContent(content)
{
return window.parser.render("${toc}\n\n" + content);
}
contentDiv.innerHTML = renderContent(`{{ content }}`);
{% if not view_only %}
let editorDiv, oldContent;
let editorDiv, oldContent, editor, savedContent = `{{ content }}`;
let linkForm = document.getElementById("link-form");
let input = document.getElementById("searchBar");
let searchHits = document.getElementById("searchHits");
Expand All @@ -86,10 +101,10 @@ <h2 id="post-title">{{ dataobj['title'] }}</h2>
}
}
window.addEventListener("load", function() {
let editor = new EasyMDE({
editor = new EasyMDE({
autofocus: true,
previewRender: function(content) {
return window.parser.render("${toc}\n\n" + content);
return renderContent(content);
},
toolbar: [
"bold",
Expand Down Expand Up @@ -124,6 +139,7 @@ <h2 id="post-title">{{ dataobj['title'] }}</h2>
})
statusBtn.classList.add("fa-check-circle");
statusBtn.classList.remove("fa-times");
savedContent = editor.value();
},
className: "fa fa-save"
},
Expand Down Expand Up @@ -222,8 +238,14 @@ <h2 id="post-title">{{ dataobj['title'] }}</h2>
function toggleEditor(btn)
{
let btnText = btn.querySelector("span");
if (btnText.textContent == "Edit") { btnText.textContent = "Hide Editor"; }
else { btnText.textContent = "Edit"; }
if (btnText.textContent == "Edit") {
btnText.textContent = "Hide Editor";
}

else {
btnText.textContent = "Edit";
contentDiv.innerHTML = renderContent(savedContent);
}
oldContent.classList.toggle("hidden"), editorDiv.classList.toggle("hidden");
}
{% endif %}
Expand Down

0 comments on commit bbe836c

Please sign in to comment.