feat: add link application support

This commit is contained in:
Erzbir
2026-08-13 17:50:33 +08:00
parent 2d450daa80
commit ff8d2377e3
9 changed files with 447 additions and 4 deletions
+16
View File
@@ -38,3 +38,19 @@ moment.comments=Toggle comments
moment.network_error=Network error. Please try again.
media.photo=Photo
page.error.title=Error
page.links.apply.title=Blogroll Application
page.links.apply.success=Your blogroll application has been submitted, please wait for review.
page.links.apply.error=Submission failed, please try again later.
page.links.apply.submit=Submit
page.links.apply.field.url=Website URL
page.links.apply.field.displayName=Website Name
page.links.apply.field.logo=Logo URL
page.links.apply.field.description=Website Description
page.links.apply.field.email=Contact Email
page.links.apply.field.backlink=Backlink URL
page.links.apply.field.feedUrls=Feed URLs
page.links.apply.field.feedUrls.placeholder=One URL per line
page.links.apply.field.captcha=CAPTCHA
page.links.apply.field.captcha.alt=CAPTCHA
page.links.apply.field.captcha.title=Click to refresh CAPTCHA
page.links.apply.field.captcha.expired=CAPTCHA expired
+16
View File
@@ -38,3 +38,19 @@ moment.comments=Toggle comments
moment.network_error=Network error. Please try again.
media.photo=Photo
page.error.title=Error
page.links.apply.title=Blogroll Application
page.links.apply.success=Your blogroll application has been submitted, please wait for review.
page.links.apply.error=Submission failed, please try again later.
page.links.apply.submit=Submit
page.links.apply.field.url=Website URL
page.links.apply.field.displayName=Website Name
page.links.apply.field.logo=Logo URL
page.links.apply.field.description=Website Description
page.links.apply.field.email=Contact Email
page.links.apply.field.backlink=Backlink URL
page.links.apply.field.feedUrls=Feed URLs
page.links.apply.field.feedUrls.placeholder=One URL per line
page.links.apply.field.captcha=CAPTCHA
page.links.apply.field.captcha.alt=CAPTCHA
page.links.apply.field.captcha.title=Click to refresh CAPTCHA
page.links.apply.field.captcha.expired=CAPTCHA expired
+16
View File
@@ -38,3 +38,19 @@ moment.comments=Mostrar u ocultar comentarios
moment.network_error=Error de red. Inténtalo de nuevo.
media.photo=Foto
page.error.title=Error
page.links.apply.title=Solicitud de inclusión en el blogroll
page.links.apply.success=Tu solicitud para el blogroll ha sido enviada, espera a que sea revisada.
page.links.apply.error=No se pudo enviar, inténtalo de nuevo más tarde.
page.links.apply.submit=Enviar
page.links.apply.field.url=URL del sitio web
page.links.apply.field.displayName=Nombre del sitio web
page.links.apply.field.logo=URL del logo
page.links.apply.field.description=Descripción del sitio web
page.links.apply.field.email=Correo de contacto
page.links.apply.field.backlink=URL del enlace de retorno
page.links.apply.field.feedUrls=URLs de suscripción
page.links.apply.field.feedUrls.placeholder=Una URL por línea
page.links.apply.field.captcha=CAPTCHA
page.links.apply.field.captcha.alt=CAPTCHA
page.links.apply.field.captcha.title=Haz clic para actualizar el CAPTCHA
page.links.apply.field.captcha.expired=El CAPTCHA ha caducado
+16
View File
@@ -38,3 +38,19 @@ moment.comments=展开或收起评论
moment.network_error=网络错误,请稍后重试
media.photo=图片
page.error.title=错误
page.links.apply.title=申请友链
page.links.apply.success=友链申请已提交, 请等待审核.
page.links.apply.error=提交失败, 请稍后再试
page.links.apply.submit=提交
page.links.apply.field.url=网站地址
page.links.apply.field.displayName=网站名称
page.links.apply.field.logo=Logo 地址
page.links.apply.field.description=网站描述
page.links.apply.field.email=联系邮箱
page.links.apply.field.backlink=反向链接地址
page.links.apply.field.feedUrls=订阅地址
page.links.apply.field.feedUrls.placeholder=每行填写一个地址
page.links.apply.field.captcha=验证码
page.links.apply.field.captcha.alt=验证码
page.links.apply.field.captcha.title=点击刷新验证码
page.links.apply.field.captcha.expired=验证码已过期
+16
View File
@@ -38,3 +38,19 @@ moment.comments=展開或收合評論
moment.network_error=網路錯誤,請稍後再試
media.photo=圖片
page.error.title=錯誤
page.links.apply.title=申請友鏈
page.links.apply.success=友鏈申請已提交, 請等待審核.
page.links.apply.error=提交失敗, 請稍後再試
page.links.apply.submit=提交
page.links.apply.field.url=網站地址
page.links.apply.field.displayName=網站名稱
page.links.apply.field.logo=Logo 地址
page.links.apply.field.description=網站描述
page.links.apply.field.email=聯絡信箱
page.links.apply.field.backlink=反向連結地址
page.links.apply.field.feedUrls=訂閱地址
page.links.apply.field.feedUrls.placeholder=每行填寫一個地址
page.links.apply.field.captcha=驗證碼
page.links.apply.field.captcha.alt=驗證碼
page.links.apply.field.captcha.title=點擊重新整理驗證碼
page.links.apply.field.captcha.expired=驗證碼已過期
+1
View File
@@ -4,6 +4,7 @@ import './module/post.js'
import './module/header.js'
import './module/effect.js'
import './module/moments.js'
import './module/links.js'
terminal.refresh();
+153
View File
@@ -0,0 +1,153 @@
import {terminal} from "../terminal.js";
const SECTION_ID = "plugin-links-apply-section";
const FORM_ID = "link-application-form";
const CAPTCHA_URL = "/links/apply/captcha";
const CAPTCHA_EXPIRE_TIME = 5 * 60 * 1000;
let captchaTimer = null;
let listenersRegistered = false;
function clearCaptchaTimer() {
if (!captchaTimer) return;
clearTimeout(captchaTimer);
captchaTimer = null;
}
function refreshCaptcha() {
const section = document.getElementById(SECTION_ID);
if (!section) {
clearCaptchaTimer();
return;
}
const captcha = section.querySelector("#link-application-captcha");
const overlay = section.querySelector("#captcha-expired-overlay");
if (!captcha || !overlay) return;
captcha.src = `${CAPTCHA_URL}?t=${Date.now()}`;
overlay.style.display = "none";
clearCaptchaTimer();
captchaTimer = setTimeout(() => {
overlay.style.display = "flex";
captchaTimer = null;
}, CAPTCHA_EXPIRE_TIME);
}
function showMessage(type, text) {
const message = document.getElementById("link-application-message");
if (!message) return;
message.textContent = text;
message.dataset.type = type;
message.hidden = false;
}
function hideMessage() {
const message = document.getElementById("link-application-message");
if (!message) return;
message.hidden = true;
message.textContent = "";
delete message.dataset.type;
}
async function submitApplication(form) {
const section = document.getElementById(SECTION_ID);
if (!section) return;
const submitButton = form.querySelector('[type="submit"]');
hideMessage();
if (submitButton) {
submitButton.disabled = true;
submitButton.setAttribute("aria-busy", "true");
}
try {
const response = await fetch(form.action, {
method: form.method || "POST",
body: new FormData(form),
credentials: "same-origin",
});
const resultUrl = new URL(response.url);
const applied = resultUrl.searchParams.get("applied");
if (applied === "success") {
showMessage(
"success",
section.dataset.successMessage
);
form.reset();
} else {
showMessage(
"error",
resultUrl.searchParams.get("message") ||
section.dataset.errorMessage
);
}
} catch {
showMessage(
"error",
section.dataset.errorMessage
);
} finally {
refreshCaptcha();
const captchaCode = form.querySelector('[name="captchaCode"]');
if (captchaCode) {
captchaCode.value = "";
}
if (submitButton) {
submitButton.disabled = false;
submitButton.removeAttribute("aria-busy");
}
}
}
function handleSubmit(event) {
const form = event.target.closest(`#${FORM_ID}`);
if (!form) return;
event.preventDefault();
submitApplication(form);
}
function handleClick(event) {
const target = event.target.closest(
'[data-link-apply-action="refresh-captcha"]'
);
if (!target) return;
if (!target.closest(`#${SECTION_ID}`)) return;
refreshCaptcha();
}
function registerLinkApplicationActions() {
if (listenersRegistered) return;
document.addEventListener("submit", handleSubmit);
document.addEventListener("click", handleClick);
listenersRegistered = true;
}
function initLinkApplication() {
clearCaptchaTimer();
if (!document.getElementById(SECTION_ID)) return;
refreshCaptcha();
}
terminal.registerInitFunc(registerLinkApplicationActions);
terminal.registerRefresh(initLinkApplication);
+118
View File
@@ -99,6 +99,107 @@
opacity: 0.8;
}
&-apply-grid {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
column-gap: calc(var(--size-theme-font) * 1);
row-gap: calc(var(--size-theme-font) * 0.9);
}
&-apply-item {
display: flex;
flex-direction: column;
gap: calc(var(--size-theme-font) * 0.3);
min-width: 0;
label {
display: flex;
align-items: baseline;
gap: calc(var(--size-theme-font) * 0.25);
margin: 0;
color: var(--color-theme-foreground);
font-size: calc(var(--size-theme-font) * 0.85);
}
&-full {
grid-column: 1 / -1;
}
&-submit {
grid-column: 1 / -1;
align-items: flex-start;
margin-top: calc(var(--size-theme-font) * 0.3);
}
}
&-required {
color: var(--color-theme-accent);
font-style: normal;
}
&-apply-captcha {
.captcha-row {
display: flex;
align-items: stretch;
gap: calc(var(--size-theme-font) * 0.5);
input {
flex: 1;
}
}
.captcha-img-wrapper {
position: relative;
flex-shrink: 0;
width: 140px;
height: 40px;
}
img {
width: 140px;
max-width: none !important;
height: 40px;
margin: 0;
padding: 0;
object-fit: contain;
background: #fff;
cursor: pointer;
border: calc(var(--width-theme-border) / 2) var(--style-theme-border) var(--color-theme-foreground);
&:hover {
border-color: var(--color-theme-accent);
}
}
.captcha-expired {
display: none;
position: absolute;
inset: 0;
align-items: center;
justify-content: center;
cursor: pointer;
background: var(--color-theme-background);
border: calc(var(--width-theme-border) / 2) var(--style-theme-border) var(--color-theme-accent);
span {
color: var(--color-theme-accent);
font-size: calc(var(--size-theme-font) * 0.75);
text-align: center;
}
}
}
&-apply-message {
margin-bottom: calc(var(--size-theme-font) * 1);
padding: calc(var(--size-theme-font) * 0.5) 0;
color: var(--color-theme-accent);
border-bottom: calc(var(--width-theme-border) / 2) var(--style-theme-table-border) var(--color-theme-accent);
}
&-apply-submit-btn {
width: auto;
}
@media (max-width: 600px) {
&-url {
display: none;
@@ -111,5 +212,22 @@
&-container {
grid-template-columns: calc(var(--size-theme-font) * 3) 1fr;
}
&-apply-grid {
grid-template-columns: 1fr;
}
&-apply-item {
&-full,
&-submit {
grid-column: auto;
}
}
&-apply-captcha {
.captcha-row {
flex-wrap: wrap;
}
}
}
}
+94 -3
View File
@@ -12,9 +12,9 @@
</header>
<section class="post-content link-section" th:each="group : ${groups}">
<div class="link-section-header">
<h2 th:text="${!#strings.isEmpty(group.spec.displayName) ? group.spec.displayName : #messages.msg('page.links.title')}">
Links
</h2>
<h2 th:text="${!#strings.isEmpty(group.spec.displayName) ? group.spec.displayName : #messages.msg('page.links.title')}">
Links
</h2>
</div>
<table class="link-table">
<tbody>
@@ -40,6 +40,97 @@
</tbody>
</table>
</section>
<section th:if="${pluginFinder.available('PluginLinks', '>=2.3.0') && linkApplicationEnabled}"
id="plugin-links-apply-section"
class="post-content link-section link-apply-section"
th:attr="data-success-message=#{page.links.apply.success}, data-error-message=#{page.links.apply.error}">
<div class="link-section-header">
<h2>[[#{page.links.apply.title}]]</h2>
</div>
<div id="link-application-message"
class="link-apply-message"
hidden></div>
<form id="link-application-form"
method="post"
th:action="@{/links/apply/submit}">
<div class="link-apply-grid">
<div class="link-apply-item">
<label for="link-url">
<span>[[#{page.links.apply.field.url}]]</span>
<em class="link-required">*</em>
</label>
<input id="link-url" name="url" type="url" required placeholder="https://">
</div>
<div class="link-apply-item">
<label for="link-displayName">
<span>[[#{page.links.apply.field.displayName}]]</span>
<em class="link-required">*</em>
</label>
<input id="link-displayName" name="displayName" type="text" required>
</div>
<div class="link-apply-item">
<label for="link-logo">
<span>[[#{page.links.apply.field.logo}]]</span>
</label>
<input id="link-logo" name="logo" type="url" placeholder="https://">
</div>
<div class="link-apply-item">
<label for="link-email">
<span>[[#{page.links.apply.field.email}]]</span>
</label>
<input id="link-email" name="email" type="email">
</div>
<div class="link-apply-item link-apply-item-full">
<label for="link-description">
<span>[[#{page.links.apply.field.description}]]</span>
</label>
<textarea id="link-description" name="description" rows="2"></textarea>
</div>
<div class="link-apply-item link-apply-item-full">
<label for="link-feedUrls">
<span>[[#{page.links.apply.field.feedUrls}]]</span>
</label>
<textarea id="link-feedUrls" name="feedUrls" rows="2"
th:placeholder="#{page.links.apply.field.feedUrls.placeholder}"></textarea>
</div>
<div class="link-apply-item">
<label for="link-backlink">
<span>[[#{page.links.apply.field.backlink}]]</span>
</label>
<input id="link-backlink" name="backlink" type="url" placeholder="https://">
</div>
<div class="link-apply-item link-apply-captcha">
<label for="link-captchaCode">
<span>[[#{page.links.apply.field.captcha}]]</span>
<em class="link-required">*</em>
</label>
<div class="captcha-row">
<input id="link-captchaCode" name="captchaCode" type="text" required minlength="5"
maxlength="5" autocomplete="off">
<div class="captcha-img-wrapper">
<img id="link-application-captcha" class="not-gallery" th:src="@{/links/apply/captcha}"
th:alt="#{page.links.apply.field.captcha.alt}"
th:title="#{page.links.apply.field.captcha.title}"
data-link-apply-action="refresh-captcha" width="140" height="40">
<div id="captcha-expired-overlay"
class="captcha-expired"
data-link-apply-action="refresh-captcha"
th:title="#{page.links.apply.field.captcha.title}">
<span>[[#{page.links.apply.field.captcha.expired}]]</span>
</div>
</div>
</div>
</div>
<div class="link-apply-item link-apply-item-submit">
<button type="submit" class="link-apply-submit-btn">
[[#{page.links.apply.submit}]]
</button>
</div>
</div>
</form>
</section>
</article>
</th:block>
</html>