Skip to content

Commit

Permalink
find my bible cta on home pages
Browse files Browse the repository at this point in the history
  • Loading branch information
wkelly17 committed Nov 21, 2024
1 parent e8b6852 commit fa4881e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 19 deletions.
43 changes: 30 additions & 13 deletions src/pages/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,19 @@ import Layout from "@layouts/Layout.astro";
import {cacheHomePageDev, getDevHomePage} from "@lib/caching";
import {
getEnglishUriMap,
getGlobal,
getHomePage,
getMenus,
getWpmlLanguages,
} from "@src/data/wp";
import {getDict} from "@src/i18n/strings";
import {adjustCmsDomLinks, getEnv, titleCase} from "@src/utils";
import {
addOptionalSectionsToCmsPages,
adjustCmsDomLinks,
collectInlineStyles,
getEnv,
titleCase,
} from "@src/utils";
import {DOMParser} from "linkedom/worker";
// !NOTE: THIS IS ONLY THE ENGLISH PAGE, HECNE THE COERCCIONES AND HARDCODES TO .EN. THIS IS DUE TO WANTING TO ROUTE THE HOME PAGE TO /, BUT THE OTHER HOME PAGES ARE LOCALE PREFIXED /ES FOR EXAMPLE
const forceRefresh = true;
Expand All @@ -31,24 +38,21 @@ const data =
if (import.meta.env.DEV) cacheHomePageDev(data);
const {title, editorBlocks, link} = data.page;
let inlineStyles: string[] = [];
const ctaGlobal = await getGlobal({
slug: "cta-interior-2",
langCode: "en",
gqlUrl,
});
const ctaGlobalAll = ctaGlobal?.allLangsGlobal;
try {
const enSrcResponse = await fetch(link);
const pageRendered = await enSrcResponse.text();
const dom = new DOMParser().parseFromString(pageRendered, "text/html");
const inlineStyleIds = [
"generateblocks-inline-css",
"global-styles-inline-css",
"generate-style-inline-css",
];
inlineStyles = inlineStyleIds.map((id) => {
const styleTag: HTMLStyleElement | undefined = dom.querySelector(`#${id}`);
if (styleTag) {
return styleTag.innerText;
}
return "";
inlineStyles = collectInlineStyles({
dom,
additionalStyles: [ctaGlobal?.inlineStyles],
});
} catch (e) {
console.error("home page fetch for inline styles failed");
Expand All @@ -69,6 +73,10 @@ const langSwitcherList = Object.values(wpmlLangDict)
return lang;
});
const langInfo = wpmlLangDict.en!;
const ctaSection = addOptionalSectionsToCmsPages({
targetLang: langInfo.code,
sectionToAdd: ctaGlobalAll,
});
const blockHtmlWithClientInjections = editorBlocks
.filter((b) => b.parentClientId == null)
Expand Down Expand Up @@ -123,5 +131,14 @@ const pageDict = getDict(langInfo.code, true)!;
);
})
}
<div class="headless-insertion overflow-hidden">
<Blocks
content={adjustCmsDomLinks({
stringToParse: ctaSection?.content!,
englishUriMap,
currentLangCode: langInfo.code,
})}
/>
</div>
</main>
</Layout>
7 changes: 1 addition & 6 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,7 @@ export function determineShowGlobal({
global: Record<string, any> | null | undefined;
}) {
// maybe opt into wp pages that opt in or out of their globals?
return (
!page.isContactPage &&
!page.isHomePage &&
!page.isScriptureEngagmentPage &&
!!global
);
return !page.isContactPage && !page.isScriptureEngagmentPage && !!global;
}

export function doShowPageTitle(page: WpPage) {
Expand Down

0 comments on commit fa4881e

Please sign in to comment.