Skip to content

Commit

Permalink
add gate
Browse files Browse the repository at this point in the history
  • Loading branch information
joevaugh4n committed Aug 6, 2024
1 parent 0b8fd62 commit 38a0d58
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 98 deletions.
8 changes: 1 addition & 7 deletions src/components/Header.astro
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@
import Socials from "./Socials.astro";
import { fetchPageContent } from "../lib/wordpress";
interface Props {
slug: string;
}
const { slug } = Astro.props;
const { content: fetchedContent } = await fetchPageContent(slug);
const { content: fetchedContent } = await fetchPageContent("pitch");
---

<header
Expand Down
17 changes: 8 additions & 9 deletions src/components/Testimonials.astro
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,17 @@
import Logo from "./atoms/Logo.astro";
import Logos from "./Logos.astro";
import TestimonialCard from "./atoms/Testimonial.astro";
import { getTestimonials } from "../lib/wordpress";
import type { Testimonial } from "../lib/wordpress";
// Logos – use svg (ideally) or webp where svgs aren't available
import BletchleyPark from "../../src/images/bp.svg";
import BM from "../../src/images/bm.svg";
import GoodLawProject from "../../src/images/goodlawproject.svg";
import HistoricEngland from "../../src/images/historicengland.svg";
import TripleC from "../../src/images/triplec.webp";
import LondonArtStudies from "../../src/images/londonartstudies.webp";
import GoodLawProject from "../../src/images/goodlawproject.svg";
import BM from "../../src/images/bm.svg";
import BletchleyPark from "../../src/images/bp.svg";
import MuseumsAssociation from "../../src/images/museumsassociation.svg";
import MuseumsGalleriesEdinburgh from "../../src/images/museumsgalleriesedinburgh.webp";
const testimonials: Testimonial[] = await getTestimonials();
import TripleC from "../../src/images/triplec.webp";
---

<section class="mb-8">
Expand Down Expand Up @@ -54,7 +51,8 @@ const testimonials: Testimonial[] = await getTestimonials();
/>
</Logos>

{testimonials.length > 0 && (
{
/*{testimonials.length > 0 && (
<div
class={`w-full overflow-hidden py-5 ${testimonials.length > 2 ? "overflow-x-auto" : ""}`}
>
Expand All @@ -71,5 +69,6 @@ const testimonials: Testimonial[] = await getTestimonials();
))}
</div>
</div>
)}
)*/
}
</section>
2 changes: 1 addition & 1 deletion src/layouts/Layout.astro
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ const {
<body>
<Nav />
<main class="min-h-screen flex flex-col px-8 my-2 max-w-7xl mx-auto">
{ready ? <slot /> : <div>🚧Under construction🚧</div>}
{ready ? <slot /> : <div class="text-center">🚧 Under construction 🚧</div>}
</main>
<Footer />
</body>
Expand Down
79 changes: 1 addition & 78 deletions src/lib/wordpress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,81 +101,4 @@ export const fetchPageContent = async (slug: string): Promise<{ title: string; c
}

return { title: pageTitle, content: pageContent };
};
function parseTestimonials(content: string): Testimonial[] {
// Remove unnecessary tags and trim the content
content = content.replace(/<\/?p>/g, '').replace(/<br\s*\/?>/g, '').trim();

// Match each testimonial block
const testimonialItems = content.match(/<span class="testimonial">\s*([\s\S]*?)\s*<\/span>/g) || [];
console.log('Matched testimonial items:', testimonialItems);

return testimonialItems.map(item => {
console.log('Processing item:', item);
const quoteMatch = item.match(/<span class="quote">\s*([\s\S]*?)\s*<\/span>/);
const authorMatch = item.match(/<span class="author">\s*([\s\S]*?)\s*<\/span>/);
const roleMatch = item.match(/<span class="role">\s*([\s\S]*?)\s*<\/span>/);
const orgMatch = item.match(/<span class="org">\s*([\s\S]*?)\s*<\/span>/);
const linkMatch = item.match(/<span class="link">\s*([\s\S]*?)\s*<\/span>/);

const quote = quoteMatch ? quoteMatch[1] : "";
const author = authorMatch ? authorMatch[1] : "";
const role = roleMatch ? roleMatch[1] : "";
const org = orgMatch ? orgMatch[1] : "";
const link = linkMatch ? linkMatch[1] : "";

console.log('Extracted values:', { quote, author, role, org, link });

return {
quote: decodeHTMLEntities(quote.trim()),
author: decodeHTMLEntities(author.trim()),
role: decodeHTMLEntities(role.trim()),
org: decodeHTMLEntities(org.trim()),
link: decodeHTMLEntities(link.trim())
};
});
}

function decodeHTMLEntities(text: string): string {
const entities: { [key: string]: string } = {
'&amp;': '&',
'&lt;': '<',
'&gt;': '>',
'&quot;': '"',
'&#39;': "'",
'&#x2F;': '/',
'&#x60;': '`',
'&#x3D;': '=',
'&nbsp;': ' ',
'&#8220;': '"',
'&#8221;': '"',
'&#8217;': "'",
'&#8216;': "'"
};
return text.replace(/&(?:#\d+|#x[\da-f]+|[a-z]+);/gi, entity =>
entities[entity] || entity.charAt(1) === '#' ? String.fromCharCode(parseInt(entity.substr(2), 10)) : entity
);
}

export async function getTestimonials(): Promise<Testimonial[]> {
try {
const { content } = await fetchPageContent('testimonials');
console.log('Fetched content:', content);
if (!content) {
console.error("No content found for testimonials page");
return [];
}
const parsedTestimonials = parseTestimonials(content);
console.log('Parsed testimonials:', JSON.stringify(parsedTestimonials, null, 2));
return parsedTestimonials;
} catch (error) {
console.error("Error fetching testimonials:", error);
return [];
}
}

// Example usage:
// (async () => {
// const testimonials = await getTestimonials();
// console.log(testimonials);
// })();
};
5 changes: 2 additions & 3 deletions src/pages/index.astro
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
// Components
import Contact from "../components/Contact.astro";
import Grid from "../components/atoms/Grid.astro";
import Header from "../components/Header.astro";
import HR from "../components/atoms/HR.astro";
import Layout from "../layouts/Layout.astro";
Expand All @@ -15,10 +14,10 @@ import Testimonials from "../components/Testimonials.astro";

<Layout
description="Adam Koszary is an expert in social media and digital engagement for museums, galleries, libraries, archives, and theatres."
ready={true}
ready={false}
title="Adam Koszary"
>
<Header slug="pitch" />
<Header />
<HR />
<Services />
<HR />
Expand Down

0 comments on commit 38a0d58

Please sign in to comment.