Skip to content

Commit

Permalink
Fixed event og img tag having wrong path
Browse files Browse the repository at this point in the history
  • Loading branch information
bhavberi committed Oct 24, 2024
1 parent dbb668a commit db54a9a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
9 changes: 4 additions & 5 deletions src/app/events/[id]/page.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@ import { getClient } from "gql/client";
import { GET_EVENT } from "gql/queries/events";
import { redirect } from "next/navigation";

import { getFile } from "utils/files";
import { getPlaceholder } from "utils/placeholder";
import { getFile, PUBLIC_URL } from "utils/files";
import EventDetails from "components/events/EventDetails";

export async function generateMetadata({ params }, parent) {
export async function generateMetadata({ params }) {
const { id } = params;

try {
const { data: { event } = {} } = await getClient().query(GET_EVENT, {
eventid: id,
});
const img = event.poster
? getFile(event.poster)
: getPlaceholder({ seed: event.name, w: 2000, h: 2000 });
? getFile(event.poster, true)
: `${PUBLIC_URL}/og-image.png`;

return {
title: event.name,
Expand Down
3 changes: 2 additions & 1 deletion src/app/layout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { AuthProvider } from "components/AuthProvider";
import { fontClass } from "components/ThemeRegistry/typography";
import TransitionProvider from "components/TransitionProvider";
import { headers } from "next/headers";
import { PUBLIC_URL } from "utils/files";

const description =
"Discover the vibrant campus life at IIIT Hyderabad through the Clubs Council. Explore diverse student-led clubs, and events that foster an inclusive community and enrich student experiences beyond the classroom. Stay updated on activities, events, and opportunities to engage and grow at IIIT-H.";
Expand Down Expand Up @@ -44,7 +45,7 @@ export const metadata = {
description: shortDescription,
images: [
{
url: "https://clubs.iiit.ac.in/og-image.png",
url: `${PUBLIC_URL}/og-image.png`,
width: 1200,
height: 630,
alt: "Clubs Council",
Expand Down
4 changes: 2 additions & 2 deletions src/components/Footer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export default function Footer() {
<Typography
variant="body2"
component={Link}
href={"https://clubs.iiit.ac.in/about/clubs-council/tech-members"}
href={"/about/clubs-council/tech-members"}
sx={{
fontWeight: 500,
textDecoration: "none",
Expand Down Expand Up @@ -224,7 +224,7 @@ export default function Footer() {
variant="body2"
component={Link}
href={
"https://clubs.iiit.ac.in/about/clubs-council/tech-members"
"/about/clubs-council/tech-members"
}
sx={{
fontWeight: 500,
Expand Down
17 changes: 13 additions & 4 deletions src/utils/files.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import dynamic from "next/dynamic";

const FILESERVER_URL = process.env.NEXT_PUBLIC_FILESERVER_URL || "http://files";
const STATIC_URL = process.env.NEXT_PUBLIC_STATIC_URL || "http://nginx/static";
export const PUBLIC_URL = process.env.NEXT_PUBLIC_HOST || "http://localhost";

// Dynamically import browser-image-resizer since it's only needed on the client side
const readAndCompressImage = dynamic(
Expand All @@ -14,23 +15,31 @@ export function getNginxFile(filepath) {
return `${STATIC_URL}/${filepath}`;
}

export function getStaticFile(filepath, filetype = "image") {
export function getStaticFile(
filepath,
filetype = "image",
public_url = false,
) {
if (filepath?.toLowerCase()?.endsWith("pdf")) {
filetype = "pdf";
} else if (filepath?.toLowerCase()?.endsWith("json")) {
filetype = "json";
}

return `${FILESERVER_URL}/files/static?filename=${filepath}&filetype=${filetype}`;
if (public_url)
return `${PUBLIC_URL}/files/static?filename=${filepath}&filetype=${filetype}`;
else
return `${FILESERVER_URL}/files/static?filename=${filepath}&filetype=${filetype}`;
}

export function getFile(filepath) {
export function getFile(filepath, public_url = false) {
if (filepath?.toLowerCase()?.startsWith("http")) {
// return the full URL if global URL
return filepath;
} else if (filepath) {
// call files service if local URL
return `${FILESERVER_URL}/files/download?filename=${filepath}`;
if (public_url) return `${PUBLIC_URL}/files/download?filename=${filepath}`;
else return `${FILESERVER_URL}/files/download?filename=${filepath}`;
}
}

Expand Down

0 comments on commit db54a9a

Please sign in to comment.