import { t as buildSeoImageUrl } from "../media-url-CKi5XSw4.mjs";

//#region src/seo/index.ts
const TRAILING_SLASH_RE = /\/$/;
const ABSOLUTE_URL_RE = /^https?:\/\//i;
/**
* Generate resolved SEO meta tags from a content item.
*
* Uses the content item's SEO fields, falling back to content data
* (title from `data.title`, description from `data.excerpt`).
*
* @param content - The content item (from getEmDashEntry, etc.)
* @param options - Configuration for title construction, canonical URLs, etc.
* @returns Resolved meta tags ready for template use
*/
function getSeoMeta(content, options = {}) {
	const { siteTitle, siteUrl, path, defaultOgImage } = options;
	const separator = options.titleSeparator || " | ";
	const seo = content.seo ?? content.data.seo ?? {
		title: null,
		description: null,
		image: null,
		canonical: null,
		noIndex: false
	};
	const pageTitle = seo.title || (typeof content.data.title === "string" ? content.data.title : null) || "";
	const fullTitle = siteTitle && pageTitle ? `${pageTitle}${separator}${siteTitle}` : pageTitle;
	const description = seo.description || (typeof content.data.excerpt === "string" ? content.data.excerpt : null) || null;
	const ogImage = seo.image ? buildSeoImageUrl(seo.image, siteUrl) : defaultOgImage ?? null;
	let canonical = null;
	if (seo.canonical) if (siteUrl && !seo.canonical.startsWith("/") && !ABSOLUTE_URL_RE.test(seo.canonical)) canonical = `${siteUrl.replace(TRAILING_SLASH_RE, "")}/${seo.canonical}`;
	else canonical = seo.canonical;
	else if (siteUrl && path) {
		const safePath = path.startsWith("/") ? path : `/${path}`;
		canonical = `${siteUrl.replace(TRAILING_SLASH_RE, "")}${safePath}`;
	}
	const robots = seo.noIndex ? "noindex, nofollow" : null;
	return {
		title: fullTitle,
		description,
		ogTitle: pageTitle || fullTitle,
		ogDescription: description,
		ogImage,
		canonical,
		robots
	};
}
/**
* Extract SEO data from a content item.
*
* Convenience accessor for the raw SEO fields without template resolution.
*
* @param content - The content item
* @returns The content's SEO fields
*/
function getContentSeo(content) {
	return content.seo ?? content.data.seo;
}

//#endregion
export { getContentSeo, getSeoMeta };
//# sourceMappingURL=index.mjs.map