Merge remote-tracking branch 'origin/main'

This commit is contained in:
rimu 2024-12-09 18:11:43 +13:00
commit d063850acd
10 changed files with 356 additions and 1 deletions

View file

@ -32,7 +32,7 @@
<h2>{{ community.title }}</h2>
</div>
<div class="card-body">
<p>{{ community.description_html|safe if community.description_html else '' }}</p>
<p>{{ community.description_html|community_links|safe if community.description_html else '' }}</p>
<p>{{ community.rules_html|safe if community.rules_html else '' }}</p>
{% if len(mods) > 0 and not community.private_mods -%}
<h3>Moderators</h3>

View file

@ -0,0 +1,165 @@
<!doctype html>
<html lang="en" data-bs-theme="auto">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title id="head-title">{% if not debug_mode %}{{ g.site.name }}{% endif %}</title>
{{ bootstrap.load_css() }}
<link href="{{ '/static/themes/' + theme() + '/css/navbars.css' }}" rel="stylesheet">
<link href="{{ '/static/themes/' + theme() + '/css/color-modes.css' }}" rel="stylesheet">
<script src="{{ '/static/themes/' + theme() + '/js/color-modes.js' }}"></script>
</head>
<body>
<div class="dropdown position-fixed bottom-0 end-0 mb-3 me-3 bd-mode-toggle">
<button class="btn btn-bd-primary py-2 dropdown-toggle d-flex align-items-center" id="bd-theme" type="button" aria-expanded="false" data-bs-toggle="dropdown" aria-label="Toggle theme (auto)">
<svg class="bi my-1 theme-icon-active" width="1em" height="1em"><use href="{{ '/static/themes/' + theme() + '/svg/color-modes.svg#circle-half' }}"></use></svg>
<span class="visually-hidden" id="bd-theme-text">Toggle theme</span>
</button>
<ul class="dropdown-menu dropdown-menu-end shadow" aria-labelledby="bd-theme-text">
<li>
<button type="button" class="dropdown-item d-flex align-items-center" data-bs-theme-value="light" aria-pressed="false">
<svg class="bi me-2 opacity-50" width="1em" height="1em"><use href="{{ '/static/themes/' + theme() + '/svg/color-modes.svg#sun-fill' }}"></use></svg>
Light
<svg class="bi ms-auto d-none" width="1em" height="1em"><use href="{{ '/static/themes/' + theme() + '/svg/color-modes.svg#check2' }}"></use></svg>
</button>
</li>
<li>
<button type="button" class="dropdown-item d-flex align-items-center" data-bs-theme-value="dark" aria-pressed="false">
<svg class="bi me-2 opacity-50" width="1em" height="1em"><use href="{{ '/static/themes/' + theme() + '/svg/color-modes.svg#moon-stars-fill' }}"></use></svg>
Dark
<svg class="bi ms-auto d-none" width="1em" height="1em"><use href="{{ '/static/themes/' + theme() + '/svg/color-modes.svg#check2' }}"></use></svg>
</button>
</li>
<li>
<button type="button" class="dropdown-item d-flex align-items-center active" data-bs-theme-value="auto" aria-pressed="true">
<svg class="bi me-2 opacity-50" width="1em" height="1em"><use href="{{ '/static/themes/' + theme() + '/svg/color-modes.svg#circle-half' }}"></use></svg>
Auto
<svg class="bi ms-auto d-none" width="1em" height="1em"><use href="{{ '/static/themes/' + theme() + '/svg/color-modes.svg#check2' }}"></use></svg>
</button>
</li>
</ul>
</div>
<nav class="navbar navbar-expand-lg sticky-top bg-body-tertiary">
<div class="container-fluid">
<a class="navbar-brand" href="/" id="navbar-title">{% if not debug_mode %}{{ g.site.name }}{% endif %}</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">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
{% if current_user.is_anonymous %}
<li class="nav-item"><a class="nav-link" href="/auth/login">{{ _('Log in') }}</a></li>
<li class="nav-item"><a class="nav-link" href="/auth/register">{{ _('Register') }}</a></li>
<li class="nav-item"><a class="nav-link" href="/donate">{{ _('Donate') }}</a></li>
{% else %}
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
{{ _('Communities') }}
</a>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="/communities">{{ _('All communities') }}</a></li>
{% if moderating_communities %}
<li><hr class="dropdown-divider"></li>
<li><h6 class="dropdown-header">{{ _('Moderating') }}</h6></li>
{% for mc in moderating_communities %}
<li>
<a class="dropdown-item" href="/c/{{ mc.link() }}">{{ mc.title }}<span class="text-body-secondary"> ({{ mc.ap_domain }})</span></a>
</li>
{% endfor %}
{% endif %}
{% if joined_communities %}
<li><hr class="dropdown-divider"></li>
<li><h6 class="dropdown-header">{{ _('Joined communities') }}</h6></li>
{% for jc in joined_communities %}
<li>
<a class="dropdown-item" href="/c/{{ jc.link() }}">{{ jc.title }}<span class="text-body-secondary"> ({{ jc.ap_domain }})</span></a>
</li>
{% endfor %}
{% endif %}
</ul>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
{{ _('Account') }}
</a>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="/u/{{ current_user.link() }}">{{ _('View profile') }}</a></li>
<li><a class="dropdown-item" href="/user/settings">{{ _('Edit profile & settings') }}</a></li>
<li><a class="dropdown-item" href="/chat">{{ _('Chats') }}</a></li>
<li><a class="dropdown-item" href="/bookmarks">{{ _('Bookmarks') }}</a></li>
<li><a class="dropdown-item" href="/alerts">{{ _('Activity Alerts') }}</a></li>
{% if current_user.hide_read_posts %}
<li><a class="dropdown-item" href="/read-posts">{{ _('Read Posts') }}</a></li>
{% endif %}
</ul>
</li>
<li class="nav-item"><a class="nav-link" href="/donate">{{ _('Donate') }}</a></li>
{% if user_access('change instance settings', current_user.id) %}
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
{{ _('Admin') }}
</a>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="/admin/site") }}">{{ _('Site profile') }}</a></li>
<li><a class="dropdown-item" href="/admin/misc">{{ _('Misc settings') }}</a></li>
<li><a class="dropdown-item" href="/admin/communities">{{ _('Communities') }}</a></li>
<li><a class="dropdown-item" href="/admin/topics">{{ _('Topics') }}</a></li>
<li><a class="dropdown-item" href="/admin/users?local_remote=local">{{ _('Users') }}</a></li>
<li><a class="dropdown-item" href="/admin/users/trash?local_remote=local">{{ _('Monitoring - users') }}</a></li>
<li><a class="dropdown-item" href="/admin/content/trash">{{ _('Monitoring - content') }}</a></li>
<li><a class="dropdown-item" href="/admin/content/spam">{{ _('Monitoring - spammy content') }}</a></li>
<li><a class="dropdown-item" href="/admin/content/deleted">{{ _('Deleted content') }}</a></li>
{% if g.site.registration_mode == 'RequireApplication' %}
<li><a class="dropdown-item" href="/admin/approve_registrations">{{ _('Registration applications') }}</a></li>
{% endif %}
<li><a class="dropdown-item" href="/admin/reports">{{ _('Moderation') }}</a></li>
<li><a class="dropdown-item" href="/admin/federation">{{ _('Federation') }}</a></li>
<li><a class="dropdown-item" href="/admin/instances">{{ _('Instances') }}</a></li>
<li><a class="dropdown-item" href="/admin/newsletter">{{ _('Newsletter') }}</a></li>
<li><a class="dropdown-item" href="/admin/activities">{{ _('Activities') }}</a></li>
<li><a class="dropdown-item" href="/admin/permissions">{{ _('Permissions') }}</a></li>
{% if debug_mode %}
<li><a class="dropdown-item" href="/dev/tools">{{ _('Dev Tools') }}</a></li>
{% endif %}
</ul>
</li>
{% endif %}
<li class="nav-item"><a class="nav-link" href="/notifications">{{ _('Inbox') }}</a></li>
<li class="nav-item"><a class="nav-link" href="/auth/logout">{{ _('Log out') }}</a></li>
{% endif %}
</ul>
</div>
</div>
</nav>
<main class="container">
{% block app_content %}{% endblock %}
<hr />
</main>
<footer class="text-center">
<small>
<a href="/donate">{{ _('Donate') }}</a><br />
<a href="/about">{{ _('About') }}</a><br />
<a href="/keyboard_shortcuts">{{ _('Keyboard shortcuts') }}</a><br/>
<a href="https://codeberg.org/rimu/pyfedi">PieFed</a> is free and open source. Please <a href="https://codeberg.org/rimu/pyfedi/issues">report bugs</a> or <a href="https://join.piefed.social/get-involved/">get involved</a>.<br />
<a href="/privacy">Privacy policy</a>
</small>
</footer>
{{ bootstrap.load_js() }}
{% if debug_mode %}
<script src="{{ '/static/themes/' + theme() + '/js/site.js' }}"></script>
{% endif %}
</body>
</html>

View file

@ -0,0 +1,29 @@
.bi {
vertical-align: -.125em;
fill: currentColor;
}
.btn-bd-primary {
--bd-violet-bg: #712cf9;
--bd-violet-rgb: 112.520718, 44.062154, 249.437846;
--bs-btn-font-weight: 600;
--bs-btn-color: var(--bs-white);
--bs-btn-bg: var(--bd-violet-bg);
--bs-btn-border-color: var(--bd-violet-bg);
--bs-btn-hover-color: var(--bs-white);
--bs-btn-hover-bg: #6528e0;
--bs-btn-hover-border-color: #6528e0;
--bs-btn-focus-shadow-rgb: var(--bd-violet-rgb);
--bs-btn-active-color: var(--bs-btn-hover-color);
--bs-btn-active-bg: #5a23c8;
--bs-btn-active-border-color: #5a23c8;
}
.bd-mode-toggle {
z-index: 1500;
}
.bd-mode-toggle .dropdown-menu .active .bi {
display: block !important;
}

View file

@ -0,0 +1,8 @@
body {
padding-bottom: 20px;
}
.navbar {
margin-bottom: 20px;
}

View file

@ -0,0 +1,21 @@
{% extends 'themes/' + theme() + '/base.html' %}
{% block app_content %}
<h3>Site Info from API</h3>
{% if not debug_mode %}
<p>(API only available in debug mode)</p>
{% else %}
<ul>
<li><span class="text-body-secondary">version: </span><span id="site_version"></span></li>
<li><span class="text-body-secondary">actor_id: </span><span id="site_actor_id"></span></li>
<li><span class="text-body-secondary">description: </span><span id="site_description"></span></li>
<li><span class="text-body-secondary">enable_downvotes: </span><span id="site_enable_downvotes"></span></li>
<li><span class="text-body-secondary">icon: </span><span id="site_icon"></span></li>
<li><span class="text-body-secondary">name: </span><span id="site_name"></span></li>
<li><span class="text-body-secondary">sidebar: </span><span id="site_sidebar"></span></li>
<li><span class="text-body-secondary">user_count: </span><span id="site_user_count"></span></li>
<li><span class="text-body-secondary">all languages: </span><span id="site_all_languages"></span></li>
</ul>
{% endif %}
{% endblock%}

View file

@ -0,0 +1,81 @@
/*!
* Color mode toggler for Bootstrap's docs (https://getbootstrap.com/)
* Copyright 2011-2024 The Bootstrap Authors
* Licensed under the Creative Commons Attribution 3.0 Unported License.
*/
(() => {
'use strict'
const getStoredTheme = () => localStorage.getItem('theme')
const setStoredTheme = theme => localStorage.setItem('theme', theme)
const getPreferredTheme = () => {
const storedTheme = getStoredTheme()
if (storedTheme) {
return storedTheme
}
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'
}
const setTheme = theme => {
if (theme === 'auto') {
document.documentElement.setAttribute('data-bs-theme', (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'))
} else {
document.documentElement.setAttribute('data-bs-theme', theme)
}
}
setTheme(getPreferredTheme())
const showActiveTheme = (theme, focus = false) => {
const themeSwitcher = document.querySelector('#bd-theme')
if (!themeSwitcher) {
return
}
const themeSwitcherText = document.querySelector('#bd-theme-text')
const activeThemeIcon = document.querySelector('.theme-icon-active use')
const btnToActive = document.querySelector(`[data-bs-theme-value="${theme}"]`)
const svgOfActiveBtn = btnToActive.querySelector('svg use').getAttribute('href')
document.querySelectorAll('[data-bs-theme-value]').forEach(element => {
element.classList.remove('active')
element.setAttribute('aria-pressed', 'false')
})
btnToActive.classList.add('active')
btnToActive.setAttribute('aria-pressed', 'true')
activeThemeIcon.setAttribute('href', svgOfActiveBtn)
const themeSwitcherLabel = `${themeSwitcherText.textContent} (${btnToActive.dataset.bsThemeValue})`
themeSwitcher.setAttribute('aria-label', themeSwitcherLabel)
if (focus) {
themeSwitcher.focus()
}
}
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => {
const storedTheme = getStoredTheme()
if (storedTheme !== 'light' && storedTheme !== 'dark') {
setTheme(getPreferredTheme())
}
})
window.addEventListener('DOMContentLoaded', () => {
showActiveTheme(getPreferredTheme())
document.querySelectorAll('[data-bs-theme-value]')
.forEach(toggle => {
toggle.addEventListener('click', () => {
const theme = toggle.getAttribute('data-bs-theme-value')
setStoredTheme(theme)
setTheme(theme)
showActiveTheme(theme, true)
})
})
})
})()

View file

@ -0,0 +1,30 @@
const url = new URL(window.location.href);
const baseUrl = `${url.protocol}//${url.host}`;
const api = baseUrl + '/api/alpha/site'
fetch(api)
.then(response => response.json())
.then(data => {
// navbar
document.querySelector('#head-title').textContent = data.site.name
document.querySelector('#navbar-title').innerHTML = '<img src="' + data.site.icon + '" alt="Logo" width="36" height="36" />' + ' ' + data.site.name
// site info
document.querySelector('#site_version').textContent = data.version
document.querySelector('#site_actor_id').textContent = data.site.actor_id
document.querySelector('#site_description').textContent = data.site.description
document.querySelector('#site_enable_downvotes').textContent = data.site.enable_downvotes
document.querySelector('#site_icon').textContent = data.site.icon
document.querySelector('#site_name').textContent = data.site.name
document.querySelector('#site_sidebar').textContent = data.site.sidebar
document.querySelector('#site_user_count').textContent = data.site.user_count
let lang_names = data.site.all_languages[0].name;
let lang_count = data.site.all_languages.length;
for (let i = 1; i < lang_count; i++) {
lang_names += ", " + data.site.all_languages[i].name;
}
document.querySelector('#site_all_languages').textContent = lang_names
})

View file

@ -0,0 +1,15 @@
<svg xmlns="http://www.w3.org/2000/svg" class="d-none">
<symbol id="check2" viewBox="0 0 16 16">
<path d="M13.854 3.646a.5.5 0 0 1 0 .708l-7 7a.5.5 0 0 1-.708 0l-3.5-3.5a.5.5 0 1 1 .708-.708L6.5 10.293l6.646-6.647a.5.5 0 0 1 .708 0z"/>
</symbol>
<symbol id="circle-half" viewBox="0 0 16 16">
<path d="M8 15A7 7 0 1 0 8 1v14zm0 1A8 8 0 1 1 8 0a8 8 0 0 1 0 16z"/>
</symbol>
<symbol id="moon-stars-fill" viewBox="0 0 16 16">
<path d="M6 .278a.768.768 0 0 1 .08.858 7.208 7.208 0 0 0-.878 3.46c0 4.021 3.278 7.277 7.318 7.277.527 0 1.04-.055 1.533-.16a.787.787 0 0 1 .81.316.733.733 0 0 1-.031.893A8.349 8.349 0 0 1 8.344 16C3.734 16 0 12.286 0 7.71 0 4.266 2.114 1.312 5.124.06A.752.752 0 0 1 6 .278z"/>
<path d="M10.794 3.148a.217.217 0 0 1 .412 0l.387 1.162c.173.518.579.924 1.097 1.097l1.162.387a.217.217 0 0 1 0 .412l-1.162.387a1.734 1.734 0 0 0-1.097 1.097l-.387 1.162a.217.217 0 0 1-.412 0l-.387-1.162A1.734 1.734 0 0 0 9.31 6.593l-1.162-.387a.217.217 0 0 1 0-.412l1.162-.387a1.734 1.734 0 0 0 1.097-1.097l.387-1.162zM13.863.099a.145.145 0 0 1 .274 0l.258.774c.115.346.386.617.732.732l.774.258a.145.145 0 0 1 0 .274l-.774.258a1.156 1.156 0 0 0-.732.732l-.258.774a.145.145 0 0 1-.274 0l-.258-.774a1.156 1.156 0 0 0-.732-.732l-.774-.258a.145.145 0 0 1 0-.274l.774-.258c.346-.115.617-.386.732-.732L13.863.1z"/>
</symbol>
<symbol id="sun-fill" viewBox="0 0 16 16">
<path d="M8 12a4 4 0 1 0 0-8 4 4 0 0 0 0 8zM8 0a.5.5 0 0 1 .5.5v2a.5.5 0 0 1-1 0v-2A.5.5 0 0 1 8 0zm0 13a.5.5 0 0 1 .5.5v2a.5.5 0 0 1-1 0v-2A.5.5 0 0 1 8 13zm8-5a.5.5 0 0 1-.5.5h-2a.5.5 0 0 1 0-1h2a.5.5 0 0 1 .5.5zM3 8a.5.5 0 0 1-.5.5h-2a.5.5 0 0 1 0-1h2A.5.5 0 0 1 3 8zm10.657-5.657a.5.5 0 0 1 0 .707l-1.414 1.415a.5.5 0 1 1-.707-.708l1.414-1.414a.5.5 0 0 1 .707 0zm-9.193 9.193a.5.5 0 0 1 0 .707L3.05 13.657a.5.5 0 0 1-.707-.707l1.414-1.414a.5.5 0 0 1 .707 0zm9.193 2.121a.5.5 0 0 1-.707 0l-1.414-1.414a.5.5 0 0 1 .707-.707l1.414 1.414a.5.5 0 0 1 0 .707zM4.464 4.465a.5.5 0 0 1-.707 0L2.343 3.05a.5.5 0 1 1 .707-.707l1.414 1.414a.5.5 0 0 1 0 .708z"/>
</symbol>
</svg>

After

Width:  |  Height:  |  Size: 2.1 KiB

View file

@ -0,0 +1,4 @@
{
"name": "X API",
"debug": true
}

View file

@ -1048,6 +1048,8 @@ def theme_list():
for dir in dirs:
if os.path.exists(f'app/templates/themes/{dir}/{dir}.json'):
theme_settings = json.loads(file_get_contents(f'app/templates/themes/{dir}/{dir}.json'))
if 'debug' in theme_settings and theme_settings['debug'] == True and not current_app.debug:
continue
result.append((dir, theme_settings['name']))
return result