Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moved Edit/Delete/Save buttons to the navigation bar #112

Open
wants to merge 30 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
fdebdfc
Trying to move buttons to the top
reactorcoremeltdown Mar 27, 2023
371e08f
Adjusted toolbar
reactorcoremeltdown Mar 27, 2023
57c4b71
Fixed wrong placement of buttons
reactorcoremeltdown Mar 27, 2023
aa1f8b5
Updated buttons and toolbars
reactorcoremeltdown Mar 27, 2023
973973c
Wrong button placement
reactorcoremeltdown Mar 27, 2023
a738b8f
Moving things around
reactorcoremeltdown Mar 27, 2023
4c21990
Trying to align navbar items
reactorcoremeltdown Mar 27, 2023
30f9966
Trying to put the save button at the top
reactorcoremeltdown Mar 27, 2023
5ac7eec
Revert "Trying to put the save button at the top"
reactorcoremeltdown Mar 27, 2023
de58ecb
Updated button classes
reactorcoremeltdown Mar 27, 2023
562e3fa
Playing around aligning items
reactorcoremeltdown Mar 27, 2023
8e4fa86
Moving stuff around
reactorcoremeltdown Mar 27, 2023
cd97383
Adjusted layout
reactorcoremeltdown Mar 27, 2023
3912b43
Tried to wrap visible buttons block into container div
reactorcoremeltdown Mar 27, 2023
2f68c1a
Revert "Tried to wrap visible buttons block into container div"
reactorcoremeltdown Mar 27, 2023
8c1a278
Poking around navbar
reactorcoremeltdown Mar 27, 2023
da590ad
Removed the div
reactorcoremeltdown Mar 27, 2023
5e32959
Added svg save icon
reactorcoremeltdown Mar 27, 2023
b2638b3
Fixed floppy icon
reactorcoremeltdown Mar 27, 2023
c7a5aba
Changed blocks placement
reactorcoremeltdown Mar 29, 2023
a467785
Regrouping
reactorcoremeltdown Mar 29, 2023
785aa18
Making Delete button collapsible
reactorcoremeltdown Mar 29, 2023
2ff70b1
Changed spacing
reactorcoremeltdown Mar 29, 2023
637835d
Using nav-link class
reactorcoremeltdown Mar 29, 2023
b2a5dce
Changed link class
reactorcoremeltdown Mar 29, 2023
7a6c1b7
Updated button class
reactorcoremeltdown Mar 29, 2023
7fd33d9
Trying to wrap a button into a link
reactorcoremeltdown Mar 29, 2023
15711b3
Removed list items for context-related buttons
reactorcoremeltdown Mar 29, 2023
1372b2b
Trying without div
reactorcoremeltdown Mar 29, 2023
1d726f6
Added an option to disable images cleanup
reactorcoremeltdown Sep 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 32 additions & 31 deletions image_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,37 +62,38 @@ def save_images(self, file):
return hash_file_name

def cleanup_images(self):
"""Deletes images not used by any page"""
saved_images = set(os.listdir(self.images_path))
# Don't delete .gitignore
saved_images.discard(".gitignore")

# Matches [*](/img/*) it does not matter if images_route is "/img" or "img"
image_link_pattern = fr"\[(.*?)\]\(({os.path.join('/', self.cfg.images_route)}.+?)\)"
image_link_regex = re.compile(image_link_pattern)
used_images = set()
# Searching for Markdown files
for root, sub_dir, files in os.walk(self.cfg.wiki_directory):
if os.path.join(self.cfg.wiki_directory, '.git') in root:
# We don't want to search there
continue
if self.images_path in root:
# Nothing interesting there too
continue
for filename in files:
path = os.path.join(root, filename)
try:
with open(path, "r", encoding="utf-8", errors="ignore") as f:
content = f.read()
matches = image_link_regex.findall(content)
for _caption, image_path in matches:
used_images.add(os.path.basename(image_path))
except:
self.logger.info(f"ignoring {path}")

not_used_images = saved_images.difference(used_images)
for not_used_image in not_used_images:
self.delete_image(not_used_image)
if self.cfg.images_cleanup:
"""Deletes images not used by any page"""
saved_images = set(os.listdir(self.images_path))
# Don't delete .gitignore
saved_images.discard(".gitignore")

# Matches [*](/img/*) it does not matter if images_route is "/img" or "img"
image_link_pattern = fr"\[(.*?)\]\(({os.path.join('/', self.cfg.images_route)}.+?)\)"
image_link_regex = re.compile(image_link_pattern)
used_images = set()
# Searching for Markdown files
for root, sub_dir, files in os.walk(self.cfg.wiki_directory):
if os.path.join(self.cfg.wiki_directory, '.git') in root:
# We don't want to search there
continue
if self.images_path in root:
# Nothing interesting there too
continue
for filename in files:
path = os.path.join(root, filename)
try:
with open(path, "r", encoding="utf-8", errors="ignore") as f:
content = f.read()
matches = image_link_regex.findall(content)
for _caption, image_path in matches:
used_images.add(os.path.basename(image_path))
except:
self.logger.info(f"ignoring {path}")

not_used_images = saved_images.difference(used_images)
for not_used_image in not_used_images:
self.delete_image(not_used_image)

def delete_image(self, image_name):
image_path = safe_join(self.images_path, image_name)
Expand Down
65 changes: 34 additions & 31 deletions templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,48 +35,47 @@

<body>
<!-- Navbar top -->
<nav class="navbar navbar-expand-lg navbar-dark bg-dark sticky-top">
<nav class="navbar navbar-expand-lg navbar-toggleable-xl navbar-dark bg-dark sticky-top">
<div class="container-fluid mx-2">
<a class="navbar-brand" href="/">Wiki</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent"
aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>

<div class="collapse navbar-collapse" id="navbarSupportedContent">
<form class="d-flex my-sm-4 my-lg-0 ms-lg-4" method="GET" action="/">
<input class="form-control me-2" type="search" placeholder="Search something..." aria-label="Search" name="q">
<button class="btn btn-primary me-2" type="submit">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-search">
<path d="M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001c.03.04.062.078.098.115l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85a1.007 1.007 0 0 0-.115-.1zM12 6.5a5.5 5.5 0 1 1-11 0 5.5 5.5 0 0 1 11 0z"></path>
</svg>
</button>
</form>

<ul class="navbar-nav mx-lg-2">
<!-- New button -->
<!--Collapsible search bar -->
<div class="collapse navbar-collapse" id="searchBar">
<ul class="navbar-nav mr-auto my-lg-0">
<!-- Search toolbar -->
<li class="nav-item">
<a class="nav-link" href="/add_new">
<button class="btn btn-success" type="button">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-file-plus" viewBox="0 0 16 16">
<path d="M8.5 6a.5.5 0 0 0-1 0v1.5H6a.5.5 0 0 0 0 1h1.5V10a.5.5 0 0 0 1 0V8.5H10a.5.5 0 0 0 0-1H8.5V6z"/>
<path d="M2 2a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V2zm10-1H4a1 1 0 0 0-1 1v12a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1V2a1 1 0 0 0-1-1z"/>
<form class="d-flex my-sm-4 my-lg-0 ms-lg-4" method="GET" action="/">
<input class="form-control me-2" type="search" placeholder="Search something..." aria-label="Search" name="q">
<button class="btn btn-primary me-2" type="submit">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-search">
<path d="M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001c.03.04.062.078.098.115l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85a1.007 1.007 0 0 0-.115-.1zM12 6.5a5.5 5.5 0 1 1-11 0 5.5 5.5 0 0 1 11 0z"></path>
</svg>
New
</button>
</a>
</form>
</li>
</ul>

<!-- List all pages -->
<ul class="navbar-nav me-auto ms-sm-2">
<li class="nav-item">
<a class="nav-link" href="/list">List all pages</a>
</li>
</ul>
</div>

<!-- Graph and toggle dark mode -->
<ul class="navbar-nav ms-auto ms-sm-2">
<!-- div class="container"> --
<!-- New button -->
<a class="nav-link" href="/add_new">
<button class="btn btn-success" type="button">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-file-plus" viewBox="0 0 16 16">
<path d="M8.5 6a.5.5 0 0 0-1 0v1.5H6a.5.5 0 0 0 0 1h1.5V10a.5.5 0 0 0 1 0V8.5H10a.5.5 0 0 0 0-1H8.5V6z"/>
<path d="M2 2a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V2zm10-1H4a1 1 0 0 0-1 1v12a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1V2a1 1 0 0 0-1-1z"/>
</svg>
New
</button>
</a>
<!-- Context related buttons -->
{% block toolbar %}{% endblock %}
<!-- /div -->
<div class="collapse navbar-collapse" id="toolbarButtons">

<ul class="navbar-nav ms-auto my-lg-0">
<!-- Graph and toggle dark mode -->
<li class="nav-item">
<a class="nav-link" href="/knowledge-graph">
<img height="25px" src="/static/images/graph_5.svg" alt="graph">
Expand All @@ -90,6 +89,10 @@
</ul>

</div>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#searchBar,#toolbarButtons,#deleteButton"
aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
</div>
</nav>

Expand Down
41 changes: 23 additions & 18 deletions templates/content.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,35 @@
</script>
{% endblock %}

{% block toolbar %}
<a class="nav-link" style="float:right; padding-right:10px" href="/edit/{% if folder %}{{ folder }}/{% endif %}{{ title }}">
<button class="btn btn-primary my-2 my-sm-0" type="submit">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-pencil-square" viewBox="0 0 16 16">
<path d="M15.502 1.94a.5.5 0 0 1 0 .706L14.459 3.69l-2-2L13.502.646a.5.5 0 0 1 .707 0l1.293 1.293zm-1.75 2.456-2-2L4.939 9.21a.5.5 0 0 0-.121.196l-.805 2.414a.25.25 0 0 0 .316.316l2.414-.805a.5.5 0 0 0 .196-.12l6.813-6.814z"/>
<path fill-rule="evenodd" d="M1 13.5A1.5 1.5 0 0 0 2.5 15h11a1.5 1.5 0 0 0 1.5-1.5v-6a.5.5 0 0 0-1 0v6a.5.5 0 0 1-.5.5h-11a.5.5 0 0 1-.5-.5v-11a.5.5 0 0 1 .5-.5H9a.5.5 0 0 0 0-1H2.5A1.5 1.5 0 0 0 1 2.5v11z"/>
</svg>
Edit
</button>
</a>
<div class="collapse navbar-collapse" id="deleteButton">
<a class="nav-link" style="float:right; padding-right:10px" data-bs-target="#removeModal" data-bs-toggle="modal" href="#removeModal">
<button class="btn btn-danger my-2 my-sm-0" type="submit">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-trash" viewBox="0 0 16 16">
<path d="M5.5 5.5A.5.5 0 0 1 6 6v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5zm2.5 0a.5.5 0 0 1 .5.5v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5zm3 .5a.5.5 0 0 0-1 0v6a.5.5 0 0 0 1 0V6z"/>
<path fill-rule="evenodd" d="M14.5 3a1 1 0 0 1-1 1H13v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V4h-.5a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1H6a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1h3.5a1 1 0 0 1 1 1v1zM4.118 4 4 4.059V13a1 1 0 0 0 1 1h6a1 1 0 0 0 1-1V4.059L11.882 4H4.118zM2.5 3V2h11v1h-11z"/>
</svg>
Delete
</button>
</a>
</div>
{% endblock %}

{% block content %}
<h1 class="title">{% if folder %}
<a class="folder" style="{% if system.darktheme %} color:whitesmoke {% else %} color:#222326 {% endif %}"
href="/list/{{ folder }}">{{ folder }}</a>/
{% endif %}
{{ title }}
<a class="nostyle" style="float:right; padding-right:10px" data-bs-target="#removeModal" data-bs-toggle="modal" href="#removeModal">
<button class="btn btn-danger my-2 my-sm-0" type="submit">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-trash" viewBox="0 0 16 16">
<path d="M5.5 5.5A.5.5 0 0 1 6 6v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5zm2.5 0a.5.5 0 0 1 .5.5v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5zm3 .5a.5.5 0 0 0-1 0v6a.5.5 0 0 0 1 0V6z"/>
<path fill-rule="evenodd" d="M14.5 3a1 1 0 0 1-1 1H13v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V4h-.5a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1H6a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1h3.5a1 1 0 0 1 1 1v1zM4.118 4 4 4.059V13a1 1 0 0 0 1 1h6a1 1 0 0 0 1-1V4.059L11.882 4H4.118zM2.5 3V2h11v1h-11z"/>
</svg>
Delete
</button>
</a>
<a class="nostyle" style="float:right; padding-right:10px" href="/edit/{% if folder %}{{ folder }}/{% endif %}{{ title }}">
<button class="btn btn-primary my-2 my-sm-0" type="submit">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-pencil-square" viewBox="0 0 16 16">
<path d="M15.502 1.94a.5.5 0 0 1 0 .706L14.459 3.69l-2-2L13.502.646a.5.5 0 0 1 .707 0l1.293 1.293zm-1.75 2.456-2-2L4.939 9.21a.5.5 0 0 0-.121.196l-.805 2.414a.25.25 0 0 0 .316.316l2.414-.805a.5.5 0 0 0 .196-.12l6.813-6.814z"/>
<path fill-rule="evenodd" d="M1 13.5A1.5 1.5 0 0 0 2.5 15h11a1.5 1.5 0 0 0 1.5-1.5v-6a.5.5 0 0 0-1 0v6a.5.5 0 0 1-.5.5h-11a.5.5 0 0 1-.5-.5v-11a.5.5 0 0 1 .5-.5H9a.5.5 0 0 0 0-1H2.5A1.5 1.5 0 0 0 1 2.5v11z"/>
</svg>
Edit
</button>
</a>

</h1>
{{ info|safe }}
Expand Down
20 changes: 11 additions & 9 deletions templates/index.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
{% extends 'base.html'%}

{%block toolbar%}
<a class="nav-link" style="float:right; padding-right:10px" href="/edit/homepage">
<button class="btn btn-primary my-2 my-sm-0" type="submit">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-pencil-square" viewBox="0 0 16 16">
<path d="M15.502 1.94a.5.5 0 0 1 0 .706L14.459 3.69l-2-2L13.502.646a.5.5 0 0 1 .707 0l1.293 1.293zm-1.75 2.456-2-2L4.939 9.21a.5.5 0 0 0-.121.196l-.805 2.414a.25.25 0 0 0 .316.316l2.414-.805a.5.5 0 0 0 .196-.12l6.813-6.814z"/>
<path fill-rule="evenodd" d="M1 13.5A1.5 1.5 0 0 0 2.5 15h11a1.5 1.5 0 0 0 1.5-1.5v-6a.5.5 0 0 0-1 0v6a.5.5 0 0 1-.5.5h-11a.5.5 0 0 1-.5-.5v-11a.5.5 0 0 1 .5-.5H9a.5.5 0 0 0 0-1H2.5A1.5 1.5 0 0 0 1 2.5v11z"/>
</svg>
Edit Homepage
</button>
</a>
{%endblock%}
{%block content%}

<a class="nostyle" style="float:right; padding-right:10px" href="/edit/homepage">
<button class="btn btn-primary my-2 my-sm-0" type="submit">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-pencil-square" viewBox="0 0 16 16">
<path d="M15.502 1.94a.5.5 0 0 1 0 .706L14.459 3.69l-2-2L13.502.646a.5.5 0 0 1 .707 0l1.293 1.293zm-1.75 2.456-2-2L4.939 9.21a.5.5 0 0 0-.121.196l-.805 2.414a.25.25 0 0 0 .316.316l2.414-.805a.5.5 0 0 0 .196-.12l6.813-6.814z"/>
<path fill-rule="evenodd" d="M1 13.5A1.5 1.5 0 0 0 2.5 15h11a1.5 1.5 0 0 0 1.5-1.5v-6a.5.5 0 0 0-1 0v6a.5.5 0 0 1-.5.5h-11a.5.5 0 0 1-.5-.5v-11a.5.5 0 0 1 .5-.5H9a.5.5 0 0 0 0-1H2.5A1.5 1.5 0 0 0 1 2.5v11z"/>
</svg>
Edit Homepage
</button>
</a>

{{homepage|safe}}

Expand Down
13 changes: 12 additions & 1 deletion templates/new.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@

{%endblock%}

{% block toolbar %}
<a class="nav-link" href=#>
<button type="submit" form="form" class="btn btn-success my-2 my-sm-0">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-file-plus" viewBox="0 0 24 24">
<path fill-rule="evenodd" clip-rule="evenodd" d="M7 2H5C4.20435 2 3.44129 2.31607 2.87868 2.87868C2.31607 3.44129 2 4.20435 2 5V19C2 19.7957 2.31607 20.5587 2.87868 21.1213C3.44129 21.6839 4.20435 22 5 22H19C19.7957 22 20.5587 21.6839 21.1213 21.1213C21.6839 20.5587 22 19.7957 22 19V8C22 7.73478 21.8946 7.48043 21.7071 7.29289L16.7071 2.29289C16.5196 2.10536 16.2652 2 16 2H9V7H16.5C16.7761 7 17 7.22386 17 7.5V8.5C17 8.77614 16.7761 9 16.5 9H8C7.44772 9 7 8.55229 7 8V2ZM6 13C5.44772 13 5 13.3838 5 13.8571V18.1429C5 18.6162 5.44772 19 6 19H18C18.5523 19 19 18.6162 19 18.1429V13.8571C19 13.3838 18.5523 13 18 13H6Z" />
</svg>

Save
</button>
</a>
{% endblock %}


{% block content %}

Expand All @@ -29,7 +41,6 @@
</div>
<input type="file" multiple>
<p id="messages"></p>
<button type="submit" class="btn btn-success mb-2">Save</button>
</form>

<script type="text/javascript" src="{{ system.web_deps["codemirror.min.js"] }}"></script>
Expand Down
1 change: 1 addition & 0 deletions wikmd-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ wiki_directory: "wiki"
homepage: "homepage.md"
homepage_title: "homepage"
images_route: "img"
images_cleanup: false
image_allowed_mime: ["image/gif", "image/jpeg", "image/png", "image/svg+xml", "image/webp"]
hide_folder_in_wiki: [".obsidian"]

Expand Down
Loading