Add post categories.

Implemented for LGB but can likely be used for WPD and other future
sites. Similar to a reddit post flair. Provides:
  - Admin panel for Category management.
  - Category selection on post submission.
  - 'Recategorize' post action.
remotes/1693045480750635534/spooky-22
Snakes 2022-08-07 02:56:13 -04:00
parent 77e5fd074d
commit 1411018f8d
24 changed files with 376 additions and 10 deletions

View File

@ -4582,6 +4582,13 @@ div.deleted.banned {
.patron[style="background-color:#FFFFFF;"] {
color: black !important;
}
.post--category-tag {
padding: 2px 5px 3px 5px;
border-radius: 5px;
font-size: 12px;
font-weight: 700;
margin-right: 0.25rem;
}
.container, .container-fluid {
background-color: var(--background) !important;
}
@ -5686,6 +5693,19 @@ g {
border-radius:.35rem;
}
.category--tag-button {
display: inline-block;
cursor: pointer;
}
#submit-categories input {
display: none;
}
#submit-categories input:checked + label {
border: 5px var(--black) double;
}
/* ------- Font Awesome ------- */
@font-face{
font-family:"Font Awesome 6 Pro";
@ -6038,6 +6058,7 @@ g {
.fa-circle-info:before{content:"\f05a"}
.fa-comment-question:before{content:"\e14b"}
.fa-sitemap:before{content:"\f0e8"}
.fa-grid:before{content:"\e195"}
.pronouns {
font-size: 9px;

View File

@ -0,0 +1,41 @@
function category_modal(id, title, sub) {
document.getElementById("category-modal-title").innerHTML = `Category: ${title}`;
xhrCategories = new XMLHttpRequest();
xhrCategories.open("GET", "/categories.json");
xhrCategories.onload = function () {
let data;
try {
data = JSON.parse(xhrCategories.response);
} catch(e) { console.log(e) }
categories = [{id: '', name: 'None', sub: sub, color_text: '#000', color_bg: '#FFF'}];
categories = [].concat(categories, data[sub]);
document.getElementById("category-modal-body").innerHTML = '';
categories.forEach(function (c) {
document.getElementById("category-modal-body").innerHTML +=
`<div class="category--tag-button" data-category="${c.id}">` +
`<span class="post--category-tag" style="color:${c.color_text}; ` +
`background-color:${c.color_bg};">${c.name}</span>` +
`</div>`;
});
document.querySelectorAll('.category--tag-button').forEach(tag =>
tag.addEventListener('click', function (e) {
reqBody = new FormData();
reqBody.append('formkey', formkey());
reqBody.append('post_id', id);
reqBody.append('category_id', tag.dataset.category);
xhrSubmit = new XMLHttpRequest();
xhrSubmit.open('POST', `/post_recategorize`);
xhrSubmit.onload = function () {
window.location.reload();
}
xhrSubmit.send(reqBody);
})
);
}
xhrCategories.send();
}

View File

@ -169,6 +169,31 @@ function checkRepost() {
}
}
function updateCategories() {
if (document.getElementById("submit-categories") == null) {
return;
}
sub = document.getElementById("sub").value;
xhrCategories = new XMLHttpRequest();
xhrCategories.open("GET", "/categories.json");
xhrCategories.onload = function () {
let data;
try {
data = JSON.parse(xhrCategories.response);
} catch(e) { console.log(e) }
document.getElementById("submit-categories").innerHTML = '';
data[sub].forEach(function (c) {
document.getElementById("submit-categories").innerHTML +=
`<input type="radio" id="category-${c.id}" name="category" value="${c.id}">` +
`<label for="category-${c.id}" class="post--category-tag" ` +
`style="color:${c.color_text}; background-color:${c.color_bg};">` +
`${c.name}</label>`;
});
}
xhrCategories.send();
}
document.addEventListener('keydown', (e) => {
if(!((e.ctrlKey || e.metaKey) && e.key === "Enter"))
@ -179,4 +204,5 @@ document.addEventListener('keydown', (e) => {
submitButton.click();
});
checkRepost()
checkRepost();
updateCategories();

View File

@ -8,6 +8,7 @@ from .user import *
from .userblock import *
from .submission import *
from .votes import *
from .category import *
from .domains import *
from .subscriptions import *
from files.__main__ import app
@ -20,4 +21,4 @@ from .saves import *
from .views import *
from .notifications import *
from .follows import *
from .lottery import *
from .lottery import *

View File

@ -0,0 +1,22 @@
from sqlalchemy import *
from sqlalchemy.orm import relationship
from files.__main__ import Base
class Category(Base):
__tablename__ = "category"
id = Column(Integer, primary_key=True, nullable=False)
name = Column(String(128), nullable=False)
sub = Column(String(20), ForeignKey("subs.name"))
color_text = Column(String(6))
color_bg = Column(String(6))
def as_json(self):
data = {
'id': self.id,
'name': self.name,
'sub': self.sub if self.sub else '',
'color_text': '#' + self.color_text,
'color_bg': '#' + self.color_bg,
}
return data

View File

@ -303,6 +303,11 @@ ACTIONTYPES = {
"icon": 'fa-thumbtack fa-rotate--45',
"color": 'bg-success'
},
'post_recategorize': {
"str": 'changed category of {self.target_link}',
"icon": 'fa-grid',
"color": 'bg-primary'
},
'purge_cache': {
"str": 'purged cache',
"icon": 'fa-memory',

View File

@ -53,6 +53,7 @@ class Submission(Base):
body = Column(String)
body_html = Column(String)
flair = Column(String)
category_id = Column(Integer, ForeignKey("category.id"))
ban_reason = Column(String)
embed_url = Column(String)
new = Column(Boolean)
@ -65,6 +66,7 @@ class Submission(Base):
comments = relationship("Comment", primaryjoin="Comment.parent_submission==Submission.id", back_populates="post")
subr = relationship("Sub", primaryjoin="foreign(Submission.sub)==remote(Sub.name)")
options = relationship("SubmissionOption", order_by="SubmissionOption.id")
category = relationship("Category", primaryjoin="Submission.category_id==Category.id")
bump_utc = deferred(Column(Integer, server_default=FetchedValue()))

View File

@ -132,6 +132,8 @@ AGENDAPOSTER_MSG_HTML = """<p>Hi <a href="/id/{id}"><img loading="lazy" src="/pp
################################################################################
PERMS = { # Minimum admin_level to perform action.
'ADMIN_CATEGORIES_CHANGE': 2, # change category on post ("recategorize")
'ADMIN_CATEGORIES_MANAGE': 3, # create/update/delete categories
'HOLE_CREATE': 0,
'CONTENT_THREADS': 3,
'FLAGS_VISIBLE': 0,
@ -146,6 +148,7 @@ PERMS = { # Minimum admin_level to perform action.
FEATURES = {
'PROCOINS': True,
'AWARDS': True,
'CATEGORIES': False,
'CHAT': True,
'PINS': True,
'COUNTRY_CLUB': True,
@ -340,6 +343,7 @@ elif SITE == 'lgbdropthet.com':
FEATURES['PROCOINS'] = False
FEATURES['AWARDS'] = False
FEATURES['CATEGORIES'] = True
FEATURES['CHAT'] = False
FEATURES['COUNTRY_CLUB'] = False
FEATURES['BADGES'] = False

View File

@ -1,5 +1,6 @@
from files.classes import *
from flask import g
from sqlalchemy.orm import joinedload
def get_id(username, v=None, graceful=False):
@ -136,6 +137,8 @@ def get_post(i, v=None, graceful=False):
Submission,
vt.c.vote_type,
blocking.c.target_id,
).options(
joinedload(Submission.category)
)
post=post.filter(Submission.id == i
@ -189,6 +192,8 @@ def get_posts(pids, v=None):
blocked.c.target_id,
).filter(
Submission.id.in_(pids)
).options(
joinedload(Submission.category)
).join(
vt, vt.c.submission_id==Submission.id, isouter=True
).join(

View File

@ -1426,6 +1426,85 @@ def admin_toggle_ban_domain(v):
return redirect("/admin/banned_domains/")
@app.get("/admin/categories")
@admin_level_required(PERMS['ADMIN_CATEGORIES_MANAGE'])
def admin_categories(v):
if not FEATURES['CATEGORIES']:
abort(404)
categories = g.db.query(Category).order_by(nullsfirst(Category.sub), Category.name).all()
return render_template("admin/categories.html", v=v, categories=categories)
@app.post("/admin/categories/add")
@admin_level_required(PERMS['ADMIN_CATEGORIES_MANAGE'])
def admin_categories_add(v):
if not FEATURES['CATEGORIES']:
abort(404)
cat_name = request.values.get("name").strip()
cat_sub = request.values.get("sub").strip().lower()
cat_color_text = request.values.get("color_text").strip().strip('#').lower()
cat_color_bg = request.values.get("color_bg").strip().strip('#').lower()
if cat_sub == '':
cat_sub = None
cat = Category(
name=cat_name,
sub=cat_sub,
color_text=cat_color_text,
color_bg=cat_color_bg
)
g.db.add(cat)
g.db.commit()
return redirect("/admin/categories")
@app.post("/admin/categories/update/<cid>")
@admin_level_required(PERMS['ADMIN_CATEGORIES_MANAGE'])
def admin_categories_update(v, cid):
if not FEATURES['CATEGORIES']:
abort(404)
cat_name = request.values.get("name").strip()
cat_color_text = request.values.get("color_text").strip().strip('#').lower()
cat_color_bg = request.values.get("color_bg").strip().strip('#').lower()
try:
cat_id = int(cid)
except:
abort(400)
cat = g.db.query(Category).filter(Category.id == cat_id).one_or_none()
if not cat:
abort(400)
cat.name = cat_name
cat.color_text = cat_color_text
cat.color_bg = cat_color_bg
g.db.add(cat)
g.db.commit()
return redirect("/admin/categories")
@app.post("/admin/categories/delete/<cid>")
@admin_level_required(PERMS['ADMIN_CATEGORIES_MANAGE'])
def admin_categories_delete(v, cid):
if not FEATURES['CATEGORIES']:
abort(404)
try:
cat_id = int(cid)
except:
abort(400)
cat = g.db.query(Category).filter(Category.id == cat_id).one_or_none()
g.db.delete(cat)
g.db.commit()
return redirect("/admin/categories")
@app.post("/admin/nuke_user")
@limiter.limit("1/second;30/minute;200/hour;1000/day")

View File

@ -697,6 +697,14 @@ def submit_post(v, sub=None):
if not sub and HOLE_REQUIRED:
return error(f"You must choose a {HOLE_NAME} for your post!")
category = None
if FEATURES['CATEGORIES']:
category_id = request.values.get('category', '')
try:
category = int(category_id)
except:
category = None
if v.is_suspended: return error("You can't perform this action while banned.")
if v.agendaposter and not v.marseyawarded: title = torture_ap(title, v.username)
@ -912,6 +920,7 @@ def submit_post(v, sub=None):
title=title[:500],
title_html=title_html,
sub=sub,
category_id=category,
ghost=ghost
)
@ -1207,6 +1216,42 @@ def toggle_post_nsfw(pid, v):
if post.over_18: return {"message": "Post has been marked as +18!"}
else: return {"message": "Post has been unmarked as +18!"}
@app.post("/post_recategorize")
@auth_required
def post_recategorize(v):
if not FEATURES['CATEGORIES']:
abort(404)
if v.admin_level < PERMS['ADMIN_CATEGORIES_CHANGE']:
abort(403)
post_id = request.values.get("post_id")
category_id = request.values.get("category_id")
try:
pid = int(post_id)
cid = None
if category_id != '':
cid = int(category_id)
except:
abort(400)
post = g.db.get(Submission, pid)
post.category_id = cid
g.db.add(post)
category_new_name = '&lt;none&gt;'
if category_id != '':
category_new_name = g.db.get(Category, cid).name
ma = ModAction(
kind='post_recategorize',
user_id=v.id,
target_submission_id=post.id,
_note=category_new_name
)
g.db.add(ma)
g.db.commit()
return {"message": "Success!"}
@app.post("/save_post/<pid>")
@limiter.limit("1/second;30/minute;200/hour;1000/day")
@limiter.limit("1/second;30/minute;200/hour;1000/day", key_func=lambda:f'{SITE}-{session.get("lo_user")}')

View File

@ -419,3 +419,15 @@ def knowledgebase(v, page):
abort(404)
return render_template(template_path, v=v)
@app.get("/categories.json")
def categories_json():
categories = g.db.query(Category).all()
data = {}
for c in categories:
sub = c.sub if c.sub else ''
sub_cats = (data[sub] if sub in data else []) + [c.as_json()]
data.update({sub: sub_cats})
return jsonify(data)

View File

@ -53,11 +53,6 @@
</ul>
{%- endif %}
<h4>API Access Control</h4>
<ul>
<li><a href="/admin/apps">Apps</a></li>
</ul>
{% if LOTTERY_ENABLED -%}
<h4>Lottery</h4>
<ul>
@ -75,6 +70,10 @@
<h4>Configuration</h4>
<ul>
<li><a href="/create_hole">Create {{ HOLE_NAME | capitalize }}</a></li>
<li><a href="/admin/apps">Apps</a></li>
{% if FEATURES['CATEGORIES'] -%}
<li><a href="/admin/categories">Categories</a></li>
{%- endif %}
</ul>
{% if v.admin_level > 2 %}

View File

@ -0,0 +1,51 @@
{% extends "default.html" %}
{% block title %}
<title>Admin — Categories</title>
{% endblock %}
{% block content %}
<div class="overflow-x-auto"><table class="table table-striped mt-3 mb-5">
<thead class="bg-primary text-white">
<tr>
<th>Category</th>
<th>{{ HOLE_NAME | capitalize }}</th>
<th>Name</th>
<th>Text Color</th>
<th>Background Color</th>
<th>Actions</th>
<th>&nbsp;</th>
</tr>
</thead>
{% for category in categories %}
<tr>
<td>{{help.submission_category_tag(category.name, category.color_text, category.color_bg)}}</td>
<td>{{category.sub if category.sub else '&mdash;'|safe}}</td>
<form action="/admin/categories/update/{{category.id}}" method="POST">
<input type="hidden" name="formkey" value="{{v.formkey}}">
<td><input name="name" type="text" value="{{category.name}}" maxlength="128" autocomplete="off" class="form-control"></td>
<td><input name="color_text" type="text" value="#{{category.color_text}}" size="7" maxlength="7" autocomplete="off" class="form-control"></td>
<td><input name="color_bg" type="text" value="#{{category.color_bg}}" size="7" maxlength="7" autocomplete="off" class="form-control"></td>
<td><input type="submit" onclick="disable(this)" class="btn btn-primary" value="Update"></td>
</form>
<form action="/admin/categories/delete/{{category.id}}" method="POST">
<input type="hidden" name="formkey" value="{{v.formkey}}">
<td><input type="submit" onclick="disable(this)" class="btn btn-primary" value="Delete"></td>
</form>
</tr>
{% endfor %}
<tr>
<form action="/admin/categories/add" method="POST">
<input type="hidden" name="formkey" value="{{v.formkey}}">
<td><input name="name" type="text" placeholder="Name" maxlength="128" autocomplete="off" class="form-control"></td>
<td><input name="sub" type="text" placeholder="{{HOLE_NAME|capitalize}} (optional)" maxlength="20" autocomplete="off" class="form-control"></td>
<td></td>
<td><input name="color_text" type="text" placeholder="#000000 (Text)" size="7" maxlength="7" autocomplete="off" class="form-control"></td>
<td><input name="color_bg" type="text" placeholder="#000000 (BG)" size="7" maxlength="7" autocomplete="off" class="form-control"></td>
<td colspan="2"><input type="submit" onclick="disable(this)" class="btn btn-primary" value="Create"></td>
</form>
</tr>
</table>
{% endblock %}

View File

@ -0,0 +1,16 @@
<div class="modal fade" id="category-modal" tabindex="-1" role="dialog" aria-labelledby="category-modal-title" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header pt-3">
<h5 id="category-modal-title"></h5>
<button class="close" data-bs-dismiss="modal" aria-label="Close">
<span aria-hidden="true"><i class="far fa-times"></i></span>
</button>
</div>
<div class="modal-body" id="category-modal-body">
</div>
</div>
</div>
</div>
<script src="{{asset('js/category_modal.js')}}"></script>

View File

@ -795,6 +795,9 @@
{% include "emoji_modal.html" %}
{% if v.admin_level > 1 %}
{% include "ban_modal.html" %}
{% if FEATURES['CATEGORIES'] -%}
{% include "category_modal.html" %}
{%- endif %}
{% endif %}
<div class="modal fade" id="deleteCommentModal" tabindex="-1" role="dialog" aria-labelledby="deleteCommentModalTitle" aria-hidden="true">

View File

@ -60,6 +60,10 @@
<a id="unclub-{{p.id}}" class="dropdown-item {% if not p.club %}d-none{% endif %} list-inline-item text-info" role="button" onclick="post_toast(this,'/toggle_club/{{p.id}}','club-{{p.id}}','unclub-{{p.id}}','d-none')"><i class="fas fa-eye"></i>Unmark club</a>
{% endif %}
{% if FEATURES['CATEGORIES'] and (v.admin_level >= PERMS['ADMIN_CATEGORIES_CHANGE']) %}
<a id="categorize-{{p.id}}" class="dropdown-item list-inline-item text-info" role="button" data-bs-toggle="modal" data-bs-target="#category-modal" onclick="category_modal('{{p.id}}', '{{p.title}}', '{{p.sub if p.sub else ''}}')"><i class="fas fa-grid text-info fa-fw"></i>Recategorize</a>
{% endif %}
{% if v.admin_level > 1 %}
{% if "/reported/" in request.path %}
{% if v.id != p.author.id %}<a class="dropdown-item list-inline-item text-danger" role="button" onclick="post_toast(this,'/ban_post/{{p.id}}')"><i class="fas fa-ban"></i>Remove</a>{% endif %}

View File

@ -18,6 +18,10 @@
<button id="unclub2-{{p.id}}" class="{% if not p.club %}d-none{% endif %} nobackground btn btn-link btn-block btn-lg text-info text-left" role="button" onclick="post_toast(this,'/toggle_club/{{p.id}}','club2-{{p.id}}','unclub2-{{p.id}}','d-none')" data-bs-dismiss="modal"><i class="fas fa-eye mr-3"></i>Unmark club</button>
{%- endif %}
{% if FEATURES['CATEGORIES'] and (v.admin_level >= PERMS['ADMIN_CATEGORIES_CHANGE']) %}
<button id="categorize2-{{p.id}}" data-bs-dismiss="modal" data-bs-toggle="modal" data-bs-target="#category-modal" onclick="category_modal('{{p.id}}', '{{p.title}}', '{{p.sub if p.sub else ''}}')" class="nobackground btn btn-link btn-block btn-lg text-info text-left" role="button"><i class="fas fa-grid mr-3"></i>Recategorize</button>
{% endif %}
<button id="distinguish2-{{p.id}}" class="{% if p.distinguish_level %}d-none{% endif %} nobackground btn btn-link btn-block btn-lg text-left text-primary" role="button" onclick="post_toast(this,'/distinguish/{{p.id}}','distinguish2-{{p.id}}','undistinguish2-{{p.id}}','d-none')" data-bs-dismiss="modal"><i class="fas fa-crown text-center text-primary mr-3"></i>Distinguish</button>
<button id="undistinguish2-{{p.id}}" class="{% if not p.distinguish_level %}d-none{% endif %} nobackground btn btn-link btn-block btn-lg text-left text-primary" role="button" onclick="post_toast(this,'/distinguish/{{p.id}}','distinguish2-{{p.id}}','undistinguish2-{{p.id}}','d-none')" data-bs-dismiss="modal"><i class="fas fa-crown text-center text-primary mr-3"></i>Undistinguish</button>

View File

@ -705,12 +705,14 @@
{% if p.realurl(v) and not v_forbid_deleted %}
<h1 id="post-title" class="card-title post-title text-left mb-md-3 {% if p.author.agendaposter %}agendaposter{% endif %}"><a {% if not v or v.newtabexternal %}target="_blank"{% endif %} rel="nofollow noopener noreferrer" href="{{p.realurl(v)}}">
{% if p.club %}<span class="patron font-weight-bolder mr-1" style="background-color:red; font-size:12px; line-height:2;">{{CC}}</span>{% endif %}
{% if p.category %}{{help.submission_category_tag(p.category.name, p.category.color_text, p.category.color_bg)}}{% endif %}
{% if p.flair %}<span class="patron font-weight-bolder mr-1" style="background-color:var(--primary); font-size:12px; line-height:2;">{{p.flair | safe}}</span>{% endif %}
{{p.realtitle(v) | safe}}
</a></h1>
{% else %}
<h1 id="post-title" class="card-title post-title text-left mb-md-3 {% if p.author.agendaposter %}agendaposter{% endif %}">
{% if p.club %}<span class="patron font-weight-bolder mr-1" style="background-color:red; font-size:12px; line-height:2;">{{CC}}</span>{% endif %}
{% if p.category %}{{help.submission_category_tag(p.category.name, p.category.color_text, p.category.color_bg)}}{% endif %}
{% if p.flair %}<span class="patron font-weight-bolder mr-1" style="background-color:var(--primary); font-size:12px; line-height:2;">{{p.flair | safe}}</span>{% endif %}
{{p.realtitle(v) | safe}}
</h1>

View File

@ -231,6 +231,7 @@
<h5 class="card-title post-title text-left w-lg-95 mb-0 pb-0 pb-md-1">
<a id="{{p.id}}-title" {% if v and v.newtab and not g.webview %}target="_blank"{% endif %} href="{{p.permalink}}" class="{% if p.sub %}sub{% elif voted and v.id == AEVANN_ID %}visited{% endif %} stretched-link {% if p.author.agendaposter %}agendaposter{% endif %}">
{% if p.club %}<span class="patron font-weight-bolder mr-1" style="background-color:red; font-size:12px; line-height:2;">{{CC}}</span>{% endif %}
{% if p.category %}{{help.submission_category_tag(p.category.name, p.category.color_text, p.category.color_bg)}}{% endif %}
{% if p.flair %}<span class="patron font-weight-bolder mr-1" style="background-color:var(--primary); font-size:12px; line-height:2;">{{p.flair | safe}}</span>{% endif %}
{{p.realtitle(v) | safe}}
</a></h5>
@ -454,6 +455,9 @@
{% include "report_post_modal.html" %}
{% if v.admin_level > 1 %}
{% include "ban_modal.html" %}
{% if FEATURES['CATEGORIES'] -%}
{% include "category_modal.html" %}
{%- endif %}
{% endif %}
{% endif %}
{% include "expanded_image_modal.html" %}

View File

@ -86,7 +86,7 @@
<div class="input-group mb2">
{%- set hole_placeholder = 'Required' if HOLE_REQUIRED else 'Optional' -%}
<input list="subs" autocomplete="off" id='sub' class="form-control" form="submitform" name="sub" oninput="savetext()" {% if sub %}value="{{sub.name}}"{% endif %} placeholder="{{hole_placeholder}}">
<input list="subs" autocomplete="off" id='sub' class="form-control" form="submitform" name="sub" oninput="savetext()" onchange="updateCategories()" {% if sub %}value="{{sub.name}}"{% endif %} placeholder="{{hole_placeholder}}">
<datalist id="subs">
{% for s in SUBS %}
<option value="{{s}}"></option>
@ -99,6 +99,11 @@
<div class="mt-1" style="font-size: min(3.5vw,14px)"><span style="color:#ffcccb ">WARNING</span>: Selecting a {{HOLE_NAME}} considerably reduces the number of people who will see your post. Don't select a {{HOLE_NAME}} unless that's what you want.</div>
{%- endif %}
{% if FEATURES['CATEGORIES'] -%}
<label class="mt-4" for="submit-categories">Category</label>
<div id="submit-categories"></div>
{%- endif %}
<label class='mt-4' for="title">Post Title</label>

View File

@ -1,6 +1,6 @@
{%-
set CACHE_VER = {
'css/main.css': 439,
'css/main.css': 440,
'css/catalog.css': 2,
'css/4chan.css': 61,
@ -18,13 +18,14 @@ set CACHE_VER = {
'js/award_modal.js': 254,
'js/bootstrap.js': 276,
'js/category_modal.js': 200,
'js/comments+submission_listing.js': 265,
'js/submission_listing.js': 261,
'js/emoji_modal.js': 312,
'js/formatting.js': 240,
'js/lottery.js': 256,
'js/marked.js': 280,
'js/submit.js': 265,
'js/submit.js': 266,
'js/userpage.js': 242,
'js/userpage_v.js': 245,
'js/lozad.js': 260,

View File

@ -3,3 +3,7 @@
{{ suffix }}
{%- endif -%}
{%- endmacro -%}
{%- macro submission_category_tag(name, color_text, color_bg) -%}
<span class="post--category-tag" style="color:#{{color_text}}; background-color:#{{color_bg}};">{{name | safe}}</span>
{%- endmacro -%}

View File

@ -0,0 +1,10 @@
CREATE TABLE category (
id serial PRIMARY KEY,
name character varying(128) NOT NULL,
sub character varying(20) REFERENCES subs(name),
color_text char(6),
color_bg char(6),
UNIQUE (name, sub)
);
ALTER TABLE submissions ADD COLUMN category_id integer REFERENCES category(id) ON DELETE SET NULL;