astro-selfie
Advanced tools
Comparing version 1.0.0 to 1.0.1
import type { AstroGlobal, AstroIntegration } from 'astro'; | ||
export default function selfie(): AstroIntegration; | ||
export declare const selfiePath: (astro: AstroGlobal) => string; | ||
export declare const selfieUrl: (astro: AstroGlobal) => URL; |
@@ -15,5 +15,7 @@ import path from 'node:path'; | ||
hooks: { | ||
// eslint-disable-next-line @typescript-eslint/naming-convention, object-shorthand | ||
'astro:config:done': ({ config }) => { | ||
publicDir = config.publicDir; | ||
}, | ||
// eslint-disable-next-line @typescript-eslint/naming-convention, object-shorthand | ||
'astro:build:done': async ({ dir, pages }) => { | ||
@@ -57,6 +59,13 @@ const screenshotsDir = new URL('og', publicDir); | ||
} | ||
export const selfiePath = (astro) => { | ||
const pathname = astro.url.pathname === '/' ? '/' : astro.url.pathname.replace(/\/$/, ''); | ||
return new URL(`/og${pathname === '/' ? '/index' : pathname}.png`, astro.site) | ||
.href; | ||
const stripTrailingSlash = (input) => { | ||
return input.replace(/\/$/, ''); | ||
}; | ||
const selfiePath = (astro) => { | ||
const pathname = astro.url.pathname === '/' | ||
? '/index' | ||
: stripTrailingSlash(astro.url.pathname); | ||
return `/og${pathname}.png`; | ||
}; | ||
export const selfieUrl = (astro) => { | ||
return new URL(selfiePath(astro), astro.site); | ||
}; |
{ | ||
"name": "astro-selfie", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Astro integration to generate page screenshots to show as Open Graph images", | ||
@@ -23,3 +23,4 @@ "license": "ISC", | ||
"dev": "tsc --watch", | ||
"test": "prettier --check source && xo" | ||
"test": "prettier --check source && xo", | ||
"prepare": "rm -rf dist && tsc" | ||
}, | ||
@@ -26,0 +27,0 @@ "files": [ |
6530
72