From f18f8d7d241f12585ddad4f2b687c0f5293b0856 Mon Sep 17 00:00:00 2001 From: zloylinux Date: Sat, 12 Jul 2025 18:54:02 +0700 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20add=20support=20for=20webme?= =?UTF-8?q?ntions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.toml | 43 ++ themes/tabi/sass/main.scss | 1 + themes/tabi/sass/parts/_webmention.scss | 149 +++++++ themes/tabi/static/js/webmention.js | 412 ++++++++++++++++++ themes/tabi/static/js/webmention.min.js | 66 +++ themes/tabi/templates/page.html | 32 +- .../partials/content_security_policy.html | 5 + .../templates/partials/extra_features.html | 15 +- .../tabi/templates/partials/webmentions.html | 51 +++ themes/tabi/theme.toml | 43 ++ 10 files changed, 805 insertions(+), 12 deletions(-) create mode 100644 themes/tabi/sass/parts/_webmention.scss create mode 100644 themes/tabi/static/js/webmention.js create mode 100644 themes/tabi/static/js/webmention.min.js create mode 100644 themes/tabi/templates/partials/webmentions.html diff --git a/config.toml b/config.toml index 047396c..f424262 100644 --- a/config.toml +++ b/config.toml @@ -278,6 +278,49 @@ voting = true page_author_hashes = "" # hash (or list of hashes) of the author. lazy_loading = true # Loads when the comments are in the viewport (using the Intersection Observer API). + +[extra.webmentions] +# To disable for a specific section or page, set webmentions = false in that page/section's front matter's [extra] section. +enable = false +# Specify the domain registered with webmention.io. +domain = "" + +# The HTML ID for the object to fill in with the webmention data. +# Defaults to "webmentions" +# id = "webmentions" + +# data configuration for the webmention.min.js script +# The base URL to use for this page. Defaults to window.location +# page_url = + +# Additional URLs to check, separated by |s +# add_urls + +# The maximum number of words to render in reply mentions. +# wordcount = 20 + +# The maximum number of mentions to retrieve. Defaults to 30. +# max_webmentions = 30 + +# By default, Webmentions render using the mf2 'url' element, which plays +# nicely with webmention bridges (such as brid.gy and telegraph) +# but allows certain spoofing attacks. If you would like to prevent +# spoofing, set this to a non-empty string (e.g. "true"). +# prevent_spoofing + +# What to order the responses by; defaults to 'published'. See +# https://github.com/aaronpk/webmention.io#api +# sort_by + +# The order to sort the responses by; defaults to 'up' (i.e. oldest +# first). See https://github.com/aaronpk/webmention.io#api +# sort_dir + +# If set to a non-empty string (e.g. "true"), will display comment-type responses +# (replies/mentions/etc.) as being part of the reactions +# (favorites/bookmarks/etc.) instead of in a separate comment list. +# comments_are_reactions = "true" + # h-card configuration # Will identify you on the indieweb (see https://microformats.org/wiki/h-card) [extra.hcard] diff --git a/themes/tabi/sass/main.scss b/themes/tabi/sass/main.scss index 3a3bc36..d3f6e5d 100644 --- a/themes/tabi/sass/main.scss +++ b/themes/tabi/sass/main.scss @@ -23,6 +23,7 @@ @use 'parts/_tags.scss'; @use 'parts/_theme-switch.scss'; @use 'parts/_zola-error.scss'; +@use 'parts/_webmention.scss'; @font-face { src: local('Open Sans'), diff --git a/themes/tabi/sass/parts/_webmention.scss b/themes/tabi/sass/parts/_webmention.scss new file mode 100644 index 0000000..b6d6338 --- /dev/null +++ b/themes/tabi/sass/parts/_webmention.scss @@ -0,0 +1,149 @@ +#webmentions { + position: relative; + z-index: 100; + margin: 0; + background-color: var(--background-color); + color: var(--text-color); + line-height: 1.2em; + + h2 { + margin-bottom: 1.5em; + font-size: 1.1em; + } + + h3 { + display: flex; + align-items: center; + font-size: 0.9em; + + svg { + margin-inline-end: 0.2rem; + } + + .svg-icon, + span { + margin-inline-end: .3rem; + } + } + + ol { + padding: 0; + } + + li, + p { + font-family: inherit; + } + + +.likes { + display: flex; + flex-wrap: wrap; + margin-top: 0.5rem; + padding: 0; + list-style: none; + + li { + position: relative; + transition: transform 0.8s ease-out, z-index 0s linear 0.4s; + margin-bottom: .375rem; + margin-inline-start: -.75rem; + + &:first-child { + margin-inline-start: 0; + } + + &:hover { + transform: scale(1.3) translateY(-4px); + z-index: 10; + transition: transform 0.05s ease-out, z-index 0s linear 0s; + } + + img { + display: block; + border: 2px solid var(--background-color, white); + border-radius: 50%; + aspect-ratio: 1/1; + width: 2.5rem; + height: 2.5rem; + object-fit: cover; + } + } + } + + .comment { + margin-bottom: 1rem; + border-radius: 10px; + background: var(--bg-0); + padding: 1rem; + overflow: hidden; + font-size: 80%; + + div { + display: flex; + flex-wrap: nowrap; + justify-content: space-between; + align-items: center; + } + + p { + margin-bottom: 0; + line-height: 1.5em; + } + + .p-author { + font-style: bold; + font-size: 1.3em; + } + + .u-url { + font-style: italic; + text-decoration: underline; + } + + .u-author { + display: flex; + align-items: center; + + img { + display: block; + margin-inline-end: .625rem; + width: 2rem; + max-width: 100%; + height: 2rem; + } + } + } + + form { + input { + flex: 1; + border: 1px solid var(--divider-color); + border-radius: 20px 0px 0px 20px; + background-color: var(--input-background-color); + padding-inline: 1rem 1rem; + padding-block: .75rem; + width: calc(60% - 2rem); + color: var(--text-color); + font-size: 1rem; + } + + button { + flex: 1; + border: 1px solid var(--divider-color); + border-radius: 0px 20px 20px 0px; + background-color: var(--input-background-color); + padding-inline: 0.7rem 0.7rem; + padding-block: .75rem; + width: 7rem; + color: var(--text-color); + font-size: 1rem; + } + + button:hover { + cursor: pointer; + background-color: var(--primary-color); + color: var(--hover-color); + } + } +} diff --git a/themes/tabi/static/js/webmention.js b/themes/tabi/static/js/webmention.js new file mode 100644 index 0000000..261b238 --- /dev/null +++ b/themes/tabi/static/js/webmention.js @@ -0,0 +1,412 @@ +/* webmention.js + +Simple thing for embedding webmentions from webmention.io into a page, client-side. + +(c)2018-2022 fluffy (http://beesbuzz.biz) +2025 mmai (https://misc.rhumbs.fr) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +Basic usage: + + + + + + +
diff --git a/themes/tabi/theme.toml b/themes/tabi/theme.toml index 3dcb701..6649e55 100644 --- a/themes/tabi/theme.toml +++ b/themes/tabi/theme.toml @@ -376,6 +376,49 @@ custom_subset = true # page_author_hashes = "" # hash (or list of hashes) of the author. # lazy_loading = true # Loads when the comments are in the viewport (using the Intersection Observer API). +[extra.webmentions] +# To disable for a specific section or page, set webmentions = false in that page/section's front matter's [extra] section. +enable = false +# Specify the domain registered with webmention.io. +# domain = "" + +# The HTML ID for the object to fill in with the webmention data. +# Defaults to "webmentions" +# id = "webmentions" + +# data configuration for the webmention.min.js script +# The base URL to use for this page. Defaults to window.location +# page_url = + +# Additional URLs to check, separated by |s +# add_urls + +# The maximum number of words to render in reply mentions. +# wordcount = 20 + +# The maximum number of mentions to retrieve. Defaults to 30. +# max_webmentions = 30 + +# By default, Webmentions render using the mf2 'url' element, which plays +# nicely with webmention bridges (such as brid.gy and telegraph) +# but allows certain spoofing attacks. If you would like to prevent +# spoofing, set this to a non-empty string (e.g. "true"). +# prevent_spoofing + +# What to order the responses by; defaults to 'published'. See +# https://github.com/aaronpk/webmention.io#api +# sort_by + +# The order to sort the responses by; defaults to 'up' (i.e. oldest +# first). See https://github.com/aaronpk/webmention.io#api +# sort_dir + +# If set to a non-empty string (e.g. "true"), will display comment-type responses +# (replies/mentions/etc.) as being part of the reactions +# (favorites/bookmarks/etc.) instead of in a separate comment list. +# comments_are_reactions = "true" + + # h-card configuration # Will identify you on the indieweb (see https://microformats.org/wiki/h-card) [extra.hcard]