Add footer to website

This commit is contained in:
itsfinniii
2026-04-19 18:03:32 +02:00
parent 2374a6bd22
commit 506a5ed14e
8 changed files with 298 additions and 8 deletions

View File

@@ -0,0 +1,110 @@
import { createDirectusConnection } from "@/lib/directus";
import { print } from 'graphql';
import type { Footer, FooterColumn, FooterSecondaryLink, FooterSocial } from "@/types/footers/footer";
import getFooterQuery from '@/graphql/footer/getFooter.graphql';
import { getImageUrl } from "@/lib/images";
export async function getFooter(): Promise<Footer> {
const client = await createDirectusConnection();
const result = await client.query(print(getFooterQuery));
const footerRecord = result['Footer'];
let dates: string[] = [
footerRecord['date_created'],
footerRecord['date_updated']
];
let footer: Footer = {
id: footerRecord['id'],
title: footerRecord['title'],
logo: {
url: getImageUrl(footerRecord['logo']['filename_disk']),
width: footerRecord['logo']['width'],
height: footerRecord['logo']['height']
},
copyright: footerRecord['copyright'],
columns: [],
socials: null,
secondaryLinks: null,
lastModified: new Date()
};
if (footerRecord['columns'] !== null) {
footerRecord['columns'].forEach((footerColumn: any) => {
const column: FooterColumn = {
id: footerColumn['id'],
title: footerColumn['title'],
links: []
};
footerColumn['links'].forEach((columnLink: any) => {
column.links.push({
id: columnLink['id'],
text: columnLink['text'],
url: columnLink['url']
});
dates.push(columnLink['date_created']);
dates.push(columnLink['date_updated']);
});
footer.columns.push(column);
dates.push(footerColumn['date_created']);
dates.push(footerColumn['date_updated']);
});
}
if (footerRecord['socials'] !== null) {
let socials: FooterSocial[] = [];
footerRecord['socials'].forEach((footerSocial: any) => {
socials.push({
id: footerSocial['id'],
name: footerSocial['name'],
url: footerSocial['url'],
icon: {
url: getImageUrl(footerSocial['icon']['filename_disk']),
width: footerSocial['icon']['width'],
height: footerSocial['icon']['height']
}
});
dates.push(footerSocial['date_created']);
dates.push(footerSocial['date_updated']);
});
footer.socials = socials;
}
if (footerRecord['secondary_links'] !== null) {
let secondaryLinks: FooterSecondaryLink[] = [];
footerRecord['secondary_links'].forEach((footerSecondaryLink: any) => {
secondaryLinks.push({
id: footerSecondaryLink['id'],
text: footerSecondaryLink['text'],
url: footerSecondaryLink['url']
});
dates.push(footerSecondaryLink['date_created']);
dates.push(footerSecondaryLink['date_updated']);
});
footer.secondaryLinks = secondaryLinks;
}
if (dates.filter(e => e !== null).length === 0) {
footer.lastModified = new Date();
}
else {
const sortedDates: string[] = dates.sort((a: string, b: string) => {
return new Date(b).getTime() - new Date(a).getTime();
});
footer.lastModified = new Date(sortedDates[0]);
}
return footer;
}