mirror of
https://github.com/litruv/lit.ruv.wtf.git
synced 2026-07-24 02:36:02 +10:00
Refactor code structure for improved readability and maintainability
This commit is contained in:
1411
website/scripts/BlogComments.js
Normal file
1411
website/scripts/BlogComments.js
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,5 @@
|
||||
import { MarkdownRenderer } from "./MarkdownRenderer.js";
|
||||
import { BlogComments } from "./BlogComments.js";
|
||||
|
||||
/**
|
||||
* Decodes markdown payload from a JSON script element.
|
||||
@@ -65,6 +66,33 @@ function renderStaticBlogPost() {
|
||||
wireCopyButtons(target);
|
||||
}
|
||||
|
||||
/**
|
||||
* Mounts Matrix-backed comments/reactions for the current blog post.
|
||||
*
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async function setupBlogComments() {
|
||||
/** @type {HTMLElement | null} */
|
||||
const mount = document.querySelector("[data-blog-comments]");
|
||||
if (!mount) return;
|
||||
|
||||
const slug = window.location.pathname
|
||||
.split("/")
|
||||
.filter(Boolean)
|
||||
.pop() || "unknown";
|
||||
|
||||
const homeserver = mount.dataset.matrixHomeserver || "https://chat.ruv.wtf";
|
||||
const roomAlias = mount.dataset.matrixRoom || "#general:chat.ruv.wtf";
|
||||
|
||||
const comments = new BlogComments({
|
||||
homeserver,
|
||||
roomAlias,
|
||||
postSlug: slug
|
||||
});
|
||||
|
||||
await comments.initialize(mount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles the compact top bar when the hero logo scrolls out of view.
|
||||
*
|
||||
@@ -200,10 +228,11 @@ function setupPeekSplines() {
|
||||
*
|
||||
* @returns {void}
|
||||
*/
|
||||
function initializeBlogPage() {
|
||||
async function initializeBlogPage() {
|
||||
renderStaticBlogPost();
|
||||
setupScrollTopBar();
|
||||
setupPeekSplines();
|
||||
await setupBlogComments();
|
||||
}
|
||||
|
||||
if (document.readyState === "loading") {
|
||||
|
||||
@@ -940,13 +940,13 @@ body.blog-page {
|
||||
}
|
||||
|
||||
|
||||
.blog-post-peek {
|
||||
display: none;
|
||||
}
|
||||
.blog-post-splines {
|
||||
display: none;
|
||||
}
|
||||
.blog-post-peek {
|
||||
display: none;
|
||||
}
|
||||
.blog-post-splines {
|
||||
display: none;
|
||||
}
|
||||
|
||||
|
||||
|
||||
.blog-post-title {
|
||||
@@ -1245,6 +1245,366 @@ body.blog-page {
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.blog-comments {
|
||||
margin-top: 28px;
|
||||
border-top: 1px solid rgba(205, 214, 244, 0.12);
|
||||
padding-top: 18px;
|
||||
}
|
||||
|
||||
.blog-comments-title {
|
||||
margin: 0 0 14px;
|
||||
font-size: 1.1rem;
|
||||
color: var(--ctp-text);
|
||||
}
|
||||
|
||||
.blog-comments-status {
|
||||
margin-top: 6px;
|
||||
margin-bottom: 12px;
|
||||
color: var(--ctp-subtext0);
|
||||
font-size: 0.86rem;
|
||||
}
|
||||
|
||||
.blog-comments-status.is-hidden {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.blog-comments.is-loading .blog-comments-status {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.blog-comments.is-loading .blog-comments-status::before {
|
||||
content: "";
|
||||
width: 12px;
|
||||
height: 12px;
|
||||
border-radius: 50%;
|
||||
border: 2px solid rgba(205, 214, 244, 0.28);
|
||||
border-top-color: var(--ctp-blue);
|
||||
animation: blog-comments-spin 0.65s linear infinite;
|
||||
}
|
||||
|
||||
.blog-comments-status.is-ok {
|
||||
color: var(--ctp-green);
|
||||
}
|
||||
|
||||
.blog-comments-status.is-error,
|
||||
.blog-comments-system.is-error {
|
||||
color: var(--ctp-red);
|
||||
}
|
||||
|
||||
.blog-comments-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
margin-bottom: 14px;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.blog-post-reactions-actions {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 6px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.blog-comment-item {
|
||||
background: rgba(24, 24, 37, 0.58);
|
||||
border: 1px solid rgba(205, 214, 244, 0.12);
|
||||
border-radius: 10px;
|
||||
padding: 10px 12px;
|
||||
}
|
||||
|
||||
.blog-comment-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 8px;
|
||||
margin-bottom: 7px;
|
||||
}
|
||||
|
||||
.blog-comment-author {
|
||||
color: var(--ctp-text);
|
||||
font-size: 0.88rem;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.blog-comment-author-group {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 5px;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.blog-comment-handle {
|
||||
color: var(--ctp-subtext0);
|
||||
font-size: 0.75rem;
|
||||
font-weight: 400;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
max-width: 180px;
|
||||
}
|
||||
|
||||
.blog-comment-owner-badge {
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.blog-comment-time {
|
||||
color: var(--ctp-subtext0);
|
||||
font-size: 0.78rem;
|
||||
}
|
||||
|
||||
.blog-comment-body {
|
||||
margin: 0;
|
||||
color: var(--ctp-subtext1);
|
||||
line-height: 1.6;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
.blog-comment-reactions {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 6px;
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
.blog-reaction-chip {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
flex-direction: row;
|
||||
gap: 4px;
|
||||
border-radius: 999px;
|
||||
border: 1px solid rgba(205, 214, 244, 0.2);
|
||||
background: rgba(49, 50, 68, 0.8);
|
||||
padding: 2px 8px;
|
||||
font-size: 0.85rem;
|
||||
line-height: 1;
|
||||
color: var(--ctp-text);
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.blog-reaction-emoji,
|
||||
.blog-reaction-count {
|
||||
display: inline;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.blog-reaction-chip.is-own {
|
||||
border-color: rgba(166, 227, 161, 0.7);
|
||||
background: rgba(166, 227, 161, 0.2);
|
||||
}
|
||||
|
||||
.blog-comment-actions {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 6px;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.blog-comment-action-btn {
|
||||
background: none;
|
||||
border: 1px solid transparent;
|
||||
border-radius: 5px;
|
||||
color: var(--ctp-subtext0);
|
||||
cursor: pointer;
|
||||
font-size: 0.75rem;
|
||||
padding: 2px 7px;
|
||||
transition: color 0.15s, background 0.15s;
|
||||
}
|
||||
|
||||
.blog-comment-action-btn:hover {
|
||||
background: rgba(205, 214, 244, 0.08);
|
||||
color: var(--ctp-text);
|
||||
}
|
||||
|
||||
.blog-comment-action-btn.is-danger:hover {
|
||||
color: var(--ctp-red);
|
||||
}
|
||||
|
||||
.blog-comment-action-btn:disabled {
|
||||
opacity: 0.5;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.blog-comment-edit-area {
|
||||
display: flex;
|
||||
gap: 6px;
|
||||
margin-top: 6px;
|
||||
}
|
||||
|
||||
.blog-comment-edit-input {
|
||||
flex: 1;
|
||||
border: 1px solid rgba(205, 214, 244, 0.2);
|
||||
background: rgba(24, 24, 37, 0.85);
|
||||
border-radius: 7px;
|
||||
color: var(--ctp-text);
|
||||
padding: 5px 9px;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.blog-comment-edit-input:focus {
|
||||
outline: none;
|
||||
border-color: var(--ctp-blue);
|
||||
}
|
||||
|
||||
.blog-reaction-btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 5px;
|
||||
border: 1px solid rgba(205, 214, 244, 0.18);
|
||||
background: rgba(49, 50, 68, 0.7);
|
||||
color: var(--ctp-text);
|
||||
border-radius: 8px;
|
||||
min-width: 34px;
|
||||
height: 28px;
|
||||
padding: 0 10px;
|
||||
cursor: pointer;
|
||||
font-size: 0.95rem;
|
||||
line-height: 1;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.blog-reaction-btn.is-own {
|
||||
border-color: rgba(166, 227, 161, 0.7);
|
||||
background: rgba(166, 227, 161, 0.15);
|
||||
}
|
||||
|
||||
.blog-reaction-btn-emoji {
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.blog-reaction-btn-count {
|
||||
font-size: 0.78rem;
|
||||
color: var(--ctp-subtext1);
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.blog-reaction-btn-count.is-hidden {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.blog-comments-composer {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr auto;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.blog-comments-input {
|
||||
width: 100%;
|
||||
border: 1px solid rgba(205, 214, 244, 0.2);
|
||||
background: rgba(24, 24, 37, 0.85);
|
||||
border-radius: 10px;
|
||||
color: var(--ctp-text);
|
||||
padding: 10px 12px;
|
||||
font-size: 0.95rem;
|
||||
}
|
||||
|
||||
.blog-comments-input:focus {
|
||||
outline: none;
|
||||
border-color: var(--ctp-blue);
|
||||
}
|
||||
|
||||
.blog-comments-send {
|
||||
border: 1px solid rgba(205, 214, 244, 0.22);
|
||||
background: rgba(137, 180, 250, 0.2);
|
||||
color: var(--ctp-text);
|
||||
border-radius: 10px;
|
||||
min-width: 78px;
|
||||
padding: 0 14px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.blog-comments-send:hover {
|
||||
background: rgba(137, 180, 250, 0.32);
|
||||
}
|
||||
|
||||
.blog-comments-send:disabled,
|
||||
.blog-comments-input:disabled {
|
||||
opacity: 0.65;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.blog-comments-system {
|
||||
margin: 0;
|
||||
color: var(--ctp-subtext0);
|
||||
font-size: 0.88rem;
|
||||
}
|
||||
|
||||
.blog-comments-identity {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
font-size: 0.85rem;
|
||||
color: var(--ctp-subtext1);
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.blog-comments-identity.is-hidden {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.blog-comments-identity-label {
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.blog-comments-identity-name {
|
||||
color: var(--ctp-text);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.blog-comments-identity-edit-btn {
|
||||
background: none;
|
||||
border: none;
|
||||
padding: 0 2px;
|
||||
cursor: pointer;
|
||||
font-size: 0.9rem;
|
||||
line-height: 1;
|
||||
opacity: 0.6;
|
||||
transition: opacity 0.15s;
|
||||
}
|
||||
|
||||
.blog-comments-identity-edit-btn:hover {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.blog-comments-identity-input {
|
||||
border: 1px solid rgba(205, 214, 244, 0.25);
|
||||
background: rgba(24, 24, 37, 0.85);
|
||||
border-radius: 6px;
|
||||
color: var(--ctp-text);
|
||||
padding: 3px 8px;
|
||||
font-size: 0.85rem;
|
||||
width: 160px;
|
||||
}
|
||||
|
||||
.blog-comments-identity-input:focus {
|
||||
outline: none;
|
||||
border-color: var(--ctp-blue);
|
||||
}
|
||||
|
||||
.blog-comments-identity-save-btn {
|
||||
background: rgba(137, 180, 250, 0.2);
|
||||
border: 1px solid rgba(137, 180, 250, 0.3);
|
||||
border-radius: 6px;
|
||||
color: var(--ctp-text);
|
||||
padding: 3px 10px;
|
||||
font-size: 0.82rem;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.blog-comments-identity-save-btn:hover {
|
||||
background: rgba(137, 180, 250, 0.35);
|
||||
}
|
||||
|
||||
@keyframes blog-comments-spin {
|
||||
from { transform: rotate(0deg); }
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
.blog-index-list {
|
||||
display: grid;
|
||||
gap: 12px;
|
||||
@@ -1281,6 +1641,14 @@ body.blog-page {
|
||||
padding: 18px 16px 22px;
|
||||
border-radius: 12px;
|
||||
}
|
||||
|
||||
.blog-comments-composer {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.blog-comments-send {
|
||||
height: 36px;
|
||||
}
|
||||
}
|
||||
|
||||
/* ─── HUD ─────────────────────────────────────────────────────────────────────── */
|
||||
|
||||
Reference in New Issue
Block a user