Implement tag mapping

- Move all admin functions to /admin URLs
- Create Liquid filters for page/post edit, category/tag link
- Update all themes to use these filters
- Add delete for pages/posts
- Move category/page functions to Admin module
This commit is contained in:
2022-05-21 00:07:16 -04:00
parent ea8d4b1c63
commit 0a21240984
35 changed files with 796 additions and 357 deletions

View File

@@ -1,6 +1,6 @@
<h2 class="my-3">{{ page_title }}</h2>
<article>
<form action="/category/save" method="post">
<form action="/admin/category/save" method="post">
<input type="hidden" name="{{ csrf.form_field_name }}" value="{{ csrf.request_token }}">
<input type="hidden" name="categoryId" value="{{ model.category_id }}">
<div class="container">

View File

@@ -1,6 +1,6 @@
<h2 class="my-3">{{ page_title }}</h2>
<article class="container">
<a href="/category/new/edit" class="btn btn-primary btn-sm mb-3">Add a New Category</a>
<a href="/admin/category/new/edit" class="btn btn-primary btn-sm mb-3">Add a New Category</a>
<table class="table table-sm table-hover">
<thead>
<tr>
@@ -18,14 +18,14 @@
{{ cat.name }}<br>
<small>
{%- if cat.post_count > 0 %}
<a href="/category/{{ cat.slug }}" target="_blank">
<a href="{{ cat | category_link }}" target="_blank">
View {{ cat.post_count }} Post{% unless cat.post_count == 1 %}s{% endunless -%}
</a>
<span class="text-muted"> &bull; </span>
{%- endif %}
<a href="/category/{{ cat.id }}/edit">Edit</a>
<a href="/admin/category/{{ cat.id }}/edit">Edit</a>
<span class="text-muted"> &bull; </span>
<a href="/category/{{ cat.id }}/delete" class="text-danger"
<a href="/admin/category/{{ cat.id }}/delete" class="text-danger"
onclick="return Admin.deleteCategory('{{ cat.id }}', '{{ cat.name }}')">
Delete
</a>

View File

@@ -9,8 +9,8 @@
Published <span class="badge rounded-pill bg-secondary">{{ model.posts }}</span>
&nbsp; Drafts <span class="badge rounded-pill bg-secondary">{{ model.drafts }}</span>
</h6>
<a href="/posts" class="btn btn-secondary me-2">View All</a>
<a href="/post/new/edit" class="btn btn-primary">Write a New Post</a>
<a href="/admin/posts" class="btn btn-secondary me-2">View All</a>
<a href="/admin/post/new/edit" class="btn btn-primary">Write a New Post</a>
</div>
</div>
</section>
@@ -22,8 +22,8 @@
All <span class="badge rounded-pill bg-secondary">{{ model.pages }}</span>
&nbsp; Shown in Page List <span class="badge rounded-pill bg-secondary">{{ model.listed_pages }}</span>
</h6>
<a href="/pages" class="btn btn-secondary me-2">View All</a>
<a href="/page/new/edit" class="btn btn-primary">Create a New Page</a>
<a href="/admin/pages" class="btn btn-secondary me-2">View All</a>
<a href="/admin/page/new/edit" class="btn btn-primary">Create a New Page</a>
</div>
</div>
</section>
@@ -37,8 +37,8 @@
All <span class="badge rounded-pill bg-secondary">{{ model.categories }}</span>
&nbsp; Top Level <span class="badge rounded-pill bg-secondary">{{ model.top_level_categories }}</span>
</h6>
<a href="/categories" class="btn btn-secondary me-2">View All</a>
<a href="/category/new/edit" class="btn btn-secondary">Add a New Category</a>
<a href="/admin/categories" class="btn btn-secondary me-2">View All</a>
<a href="/admin/category/new/edit" class="btn btn-secondary">Add a New Category</a>
</div>
</div>
</section>

View File

@@ -21,14 +21,15 @@
{% if logged_on -%}
<ul class="navbar-nav">
{{ "admin" | nav_link: "Dashboard" }}
{{ "pages" | nav_link: "Pages" }}
{{ "posts" | nav_link: "Posts" }}
{{ "categories" | nav_link: "Categories" }}
{{ "admin/pages" | nav_link: "Pages" }}
{{ "admin/posts" | nav_link: "Posts" }}
{{ "admin/categories" | nav_link: "Categories" }}
{{ "admin/tag-mappings" | nav_link: "Tag Mappings" }}
</ul>
{%- endif %}
<ul class="navbar-nav flex-grow-1 justify-content-end">
{% if logged_on -%}
{{ "user/edit" | nav_link: "Edit User" }}
{{ "admin/user/edit" | nav_link: "Edit User" }}
{{ "user/log-off" | nav_link: "Log Off" }}
{%- else -%}
{{ "user/log-on" | nav_link: "Log On" }}

View File

@@ -1,6 +1,6 @@
<h2 class="my-3">{{ page_title }}</h2>
<article>
<form action="/page/save" method="post">
<form action="/admin/page/save" method="post">
<input type="hidden" name="{{ csrf.form_field_name }}" value="{{ csrf.request_token }}">
<input type="hidden" name="pageId" value="{{ model.page_id }}">
<div class="container">

View File

@@ -1,6 +1,6 @@
<h2 class="my-3">{{ page_title }}</h2>
<article class="container">
<a href="/page/new/edit" class="btn btn-primary btn-sm mb-3">Create a New Page</a>
<a href="/admin/page/new/edit" class="btn btn-primary btn-sm mb-3">Create a New Page</a>
<table class="table table-sm table-hover">
<thead>
<tr>
@@ -19,9 +19,12 @@
<small>
<a href="/{% unless pg.is_default %}{{ pg.permalink }}{% endunless %}" target="_blank">View Page</a>
<span class="text-muted"> &bull; </span>
<a href="/page/{{ pg.id }}/edit">Edit</a>
<a href="{{ pg.id | edit_page_link }}">Edit</a>
<span class="text-muted"> &bull; </span>
<a href="#" class="text-danger">Delete</a>
<a href="/admin/page/{{ pg.id }}/delete" class="text-danger"
onclick="return Admin.deletePage('{{ pg.id }}', '{{ pg.title }}')">
Delete
</a>
</small>
</td>
<td>/{% unless pg.is_default %}{{ pg.permalink }}{% endunless %}</td>
@@ -30,4 +33,7 @@
{%- endfor %}
</tbody>
</table>
<form method="post" id="deleteForm">
<input type="hidden" name="{{ csrf.form_field_name }}" value="{{ csrf.request_token }}">
</form>
</article>

View File

@@ -1,6 +1,6 @@
<h2 class="my-3">{{ page_title }}</h2>
<article>
<form action="/{{ model.entity }}/permalinks" method="post">
<form action="/admin/{{ model.entity }}/permalinks" method="post">
<input type="hidden" name="{{ csrf.form_field_name }}" value="{{ csrf.request_token }}">
<input type="hidden" name="id" value="{{ model.id }}">
<div class="container">
@@ -10,7 +10,7 @@
<strong>{{ model.current_title }}</strong><br>
<small class="text-muted">
<span class="fst-italic">{{ model.current_permalink }}</span><br>
<a href="/{{ model.entity }}/{{ model.id }}/edit">&laquo; Back to Edit {{ model.entity | capitalize }}</a>
<a href="/admin/{{ model.entity }}/{{ model.id }}/edit">&laquo; Back to Edit {{ model.entity | capitalize }}</a>
</small>
</p>
</div>

View File

@@ -1,6 +1,6 @@
<h2 class="my-3">{{ page_title }}</h2>
<article>
<form action="/post/save" method="post">
<form action="/admin/post/save" method="post">
<input type="hidden" name="{{ csrf.form_field_name }}" value="{{ csrf.request_token }}">
<input type="hidden" name="postId" value="{{ model.post_id }}">
<div class="container">

View File

@@ -1,6 +1,6 @@
<h2 class="my-3">{{ page_title }}</h2>
<article class="container">
<a href="/post/new/edit" class="btn btn-primary btn-sm mb-3">Write a New Post</a>
<a href="/admin/post/new/edit" class="btn btn-primary btn-sm mb-3">Write a New Post</a>
<table class="table table-sm table-hover">
<thead>
<tr>
@@ -25,9 +25,12 @@
<small>
<a href="/{{ post.permalink }}" target="_blank">View Post</a>
<span class="text-muted"> &bull; </span>
<a href="/post/{{ post.id }}/edit">Edit</a>
<a href="{{ post.id | edit_post_link }}">Edit</a>
<span class="text-muted"> &bull; </span>
<a href="#" class="text-danger">Delete</a>
<a href="/admin/post/{{ pg.id }}/delete" class="text-danger"
onclick="return Admin.deletePost('{{ post.id }}', '{{ post.title }}')">
Delete
</a>
</small>
</td>
<td class="no-wrap">{{ model.authors | value: post.author_id }}</td>
@@ -51,4 +54,7 @@
</div>
</div>
{% endif %}
<form method="post" id="deleteForm">
<input type="hidden" name="{{ csrf.form_field_name }}" value="{{ csrf.request_token }}">
</form>
</article>

View File

@@ -0,0 +1,35 @@
<h2 class="my-3">{{ page_title }}</h2>
<article>
<form action="/admin/tag-mapping/save" method="post">
<input type="hidden" name="{{ csrf.form_field_name }}" value="{{ csrf.request_token }}">
<input type="hidden" name="id" value="{{ model.id }}">
<div class="container">
<div class="row mb-3">
<div class="col">
<a href="/admin/tag-mappings">&laquo; Back to Tag Mappings</a>
</div>
</div>
<div class="row mb-3">
<div class="col-6 col-lg-4 pb-3">
<div class="form-floating">
<input type="text" name="tag" id="tag" class="form-control" placeholder="Tag" autofocus required
value="{{ model.tag }}">
<label for="tag">Tag</label>
</div>
</div>
<div class="col-6 col-lg-4 pb-3">
<div class="form-floating">
<input type="text" name="urlValue" id="urlValue" class="form-control" placeholder="URL Value" required
value="{{ model.url_value }}">
<label for="urlValue">URL Value</label>
</div>
</div>
</div>
<div class="row mb-3">
<div class="col">
<button type="submit" class="btn btn-primary">Save Changes</button>
</div>
</div>
</div>
</form>
</article>

View File

@@ -0,0 +1,32 @@
<h2 class="my-3">{{ page_title }}</h2>
<article class="container">
<a href="/admin/tag-mapping/new/edit" class="btn btn-primary btn-sm mb-3">Add a New Tag Mapping</a>
<table class="table table-sm table-hover">
<thead>
<tr>
<th scope="col">Tag</th>
<th scope="col">URL Value</th>
</tr>
</thead>
<tbody>
{% for map in mappings -%}
{%- assign map_id = mapping_ids | value: map.tag -%}
<tr>
<td class="no-wrap">
{{ map.tag }}<br>
<small>
<a href="/admin/tag-mapping/{{ map_id }}/delete" class="text-danger"
onclick="return Admin.deleteTagMapping('{{ map_id }}', '{{ map.tag }}')">
Delete
</a>
</small>
</td>
<td>{{ map.url_value }}</td>
</tr>
{%- endfor %}
</tbody>
</table>
<form method="post" id="deleteForm">
<input type="hidden" name="{{ csrf.form_field_name }}" value="{{ csrf.request_token }}">
</form>
</article>

View File

@@ -1,6 +1,6 @@
<h2 class="my-3">{{ page_title }}</h2>
<article>
<form action="/user/save" method="post">
<form action="/admin/user/save" method="post">
<input type="hidden" name="{{ csrf.form_field_name }}" value="{{ csrf.request_token }}">
<div class="container">
<div class="row mb-3">

View File

@@ -2,7 +2,7 @@
<article class="content auto">
{{ page.text }}
{% if logged_on -%}
<p><small><a href="/page/{{ page.id }}/edit">Edit This Page</a></small></p>
<p><small><a href="{{ page.id | edit_page_link }}">Edit This Page</a></small></p>
{% endif %}
</article>
<aside class="app-sidebar">

View File

@@ -3,6 +3,6 @@
{{ page.text }}
<p><br><a href="/" title="Home">&laquo; Home</a></p>
{% if logged_on -%}
<p><small><a href="/page/{{ page.id }}/edit">Edit This Page</a></small></p>
<p><small><a href="{{ page.id | edit_page_link }}">Edit This Page</a></small></p>
{% endif %}
</article>

View File

@@ -94,7 +94,7 @@
{%- endif %}
<p><br><a href="/solutions">&laquo; Back to All Solutions</a></p>
{% if logged_on -%}
<p><small><a href="/page/{{ page.id }}/edit">Edit This Page</a></small></p>
<p><small><a href="{{ page.id | edit_page_link }}">Edit This Page</a></small></p>
{% endif %}
</article>
</div>

View File

@@ -24,7 +24,7 @@
</span>
{% if logged_on %}
<span>
<a href="/post/{{ post.id }}/edit"><i class="fa fa-pencil-square-o"></i> Edit Post</a>
<a href="{{ post.id | edit_post_link }}"><i class="fa fa-pencil-square-o"></i> Edit Post</a>
</span>
{% endif %}
</h4>

View File

@@ -15,7 +15,7 @@
{% endif %}
<span title="Author"><i class="fa fa-user"></i> {{ model.authors | value: post.author_id }}</span>
{% if logged_on %}
<span><a href="/post/{{ post.id }}/edit"><i class="fa fa-pencil-square-o"></i> Edit Post</a></span>
<span><a href="{{ post.id | edit_post_link }}"><i class="fa fa-pencil-square-o"></i> Edit Post</a></span>
{% endif %}
</h4>
<div>{{ post.text }}</div>
@@ -27,7 +27,7 @@
{% assign cat = categories | where: "id", cat_id | first %}
<span class="no-wrap">
<i class="fa fa-folder-open-o" title="Category"></i>
<a href="/category/{{ cat.slug }}/" title="Categorized under &ldquo;{{ cat.name | escape }}&rdquo;">
<a href="{{ cat.slug | category_link }}" title="Categorized under &ldquo;{{ cat.name | escape }}&rdquo;">
{{ cat.name }}
</a> &nbsp; &nbsp;
</span>
@@ -40,7 +40,7 @@
Tagged &nbsp;
{% for tag in post.tags %}
<span class="no-wrap">
<a href="/tag/{{ tag | replace: " ", "+" }}/" title="Posts tagged &ldquo;{{ tag | escape }}&rdquo;">
<a href="{{ tag | tag_link }}" title="Posts tagged &ldquo;{{ tag | escape }}&rdquo;" rel="tag">
<i class="fa fa-tag"></i> {{ tag }}
</a> &nbsp; &nbsp;
</span>

View File

@@ -23,7 +23,7 @@
{%- for cat_id in post.category_ids %}
{%- assign cat = categories | where: "id", cat_id | first -%}
<span>
<a href="/category/{{ cat.slug }}/"
<a href="{{ cat | category_link }}"
title="Categorized under {{ cat.name | strip_html | escape }}" rel="tag">{{ cat.name }}</a></span>
{%- endfor %}
</small><br>
@@ -34,12 +34,12 @@
Tagged
{%- for tag in post.tags %}
<span>
<a href="/tag/{{ tag | replace: " ", "+" }}/"
title="Tagged &ldquo;{{ tag | escape }}&rdquo;" rel="tag">{{ tag }}</a></span>
<a href="{{ tag | tag_link }}" title="Tagged &ldquo;{{ tag | escape }}&rdquo;" rel="tag">{{ tag }}</a>
</span>
{%- endfor %}
</small><br>
{%- endif %}
{%- if logged_on %}<small><a href="/post/{{ post.id }}/edit">Edit Post</a></small>{% endif %}
{%- if logged_on %}<small><a href="{{ post.id | edit_post_link }}">Edit Post</a></small>{% endif %}
</article>
{%- endfor %}
<div class="bottom-nav" role="navigation">

View File

@@ -57,7 +57,7 @@
{% for cat in categories -%}
{%- assign indent = cat.parent_names | size -%}
<li class="cat-list-item"{% if indent > 0 %} style="padding-left:{{ indent }}rem;"{% endif %}>
<a href="/category/{{ cat.slug }}/" class="cat-list-link">{{ cat.name }}</a>
<a href="{{ cat | category_link }}" class="cat-list-link">{{ cat.name }}</a>
<span class="cat-list-count">{{ cat.post_count }}</span>
</li>
{%- endfor %}

View File

@@ -1,5 +1,5 @@
<article class="auto">
<h1 class="entry-title">{{ page.title }}</h1>
<div class="entry-content">{{ page.text }}</div>
{%- if logged_on %}<p><small><a href="/page/{{ page.id }}/edit">Edit Page</a></small></p>{% endif %}
{%- if logged_on %}<p><small><a href="{{ page.id | edit_page_link }}">Edit Page</a></small></p>{% endif %}
</article>

View File

@@ -13,8 +13,11 @@
{%- for cat_id in post.category_ids %}
{%- assign cat = categories | where: "id", cat_id | first -%}
<span>
<a href="/category/{{ cat.slug }}/"
title="Categorized under {{ cat.name | strip_html | escape }}" rel="tag">{{ cat.name }}</a></span>
<a href="{{ cat | category_link }}" title="Categorized under {{ cat.name | strip_html | escape }}"
rel="tag">
{{ cat.name }}
</a>
</span>
{%- endfor %}
</small>
{%- endif %}
@@ -28,14 +31,14 @@
Tagged
{%- for tag in post.tags %}
<span>
<a href="/tag/{{ tag | replace: " ", "+" }}/"
title="Tagged &ldquo;{{ tag | escape }}&rdquo;" rel="tag">{{ tag }}</a></span>
<a href="{{ tag | tag_link }}" title="Tagged &ldquo;{{ tag | escape }}&rdquo;" rel="tag">{{ tag }}</a>
</span>
{%- endfor %}
</span> &bull;
{%- endif %}
Bookmark the
<a href="/{{ post.permalink }}" rel="bookmark"
title="Permanent link to &ldquo;{{ post.title | strip_html | escape }}&rdquo;">permalink</a>
{%- if logged_on %} &bull; <a href="/post/{{ post.id }}/edit">Edit Post</a>{% endif %}
{%- if logged_on %} &bull; <a href="{{ post.id | edit_post_link }}">Edit Post</a>{% endif %}
</div>
</article>