Skip to content

Commit 1eada7f

Browse files
committed
Refactor webmentions touse astro:env/client, update validation of token
1 parent e76dc53 commit 1eada7f

2 files changed

Lines changed: 5 additions & 15 deletions

File tree

‎src/components/WebMentions/server.ts‎

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* @see https://webmention.io/
55
* @see https://github.com/aaronpk/webmention.io
66
*/
7+
import { WEBMENTION_IO_TOKEN } from 'astro:env/client'
78

89
export interface WebmentionAuthor {
910
url?: string
@@ -85,23 +86,12 @@ const cleanWebmention = (entry: Webmention): Webmention => {
8586
* @param token - Optional webmention.io API token (from env var)
8687
* @returns Array of processed webmentions
8788
*/
88-
export const fetchWebmentions = async (
89-
url: string,
90-
token?: string
91-
): Promise<Webmention[]> => {
92-
// Get token from environment if not provided
93-
const apiToken = token || import.meta.env['WEBMENTION_IO_TOKEN']
94-
95-
if (!apiToken) {
96-
console.warn('⚠️ WEBMENTION_IO_TOKEN not found. Webmentions will not be fetched.')
97-
return []
98-
}
99-
89+
export const fetchWebmentions = async (url: string): Promise<Webmention[]> => {
10090
try {
10191
// Fetch from webmention.io API
10292
const apiUrl = new URL('https://webmention.io/api/mentions.jf2')
10393
apiUrl.searchParams.set('target', url)
104-
apiUrl.searchParams.set('token', apiToken)
94+
apiUrl.searchParams.set('token', WEBMENTION_IO_TOKEN)
10595
apiUrl.searchParams.set('per-page', '1000')
10696

10797
const response = await fetch(apiUrl.toString(), {

‎src/lib/config/environmentalVariableValidation.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ export const environmentalVariablesConfig: AstroUserConfig['env'] = {
143143
* Site uses ConvertKit for managing newsletter subscriptions
144144
*/
145145
WEBMENTION_IO_TOKEN: envField.string({
146-
access: 'secret',
147-
context: 'server',
146+
access: 'public',
147+
context: 'client',
148148
optional: false,
149149
}),
150150
},

0 commit comments

Comments
 (0)