Skip to content

Commit

Permalink
Merge branch 'main' into charts
Browse files Browse the repository at this point in the history
  • Loading branch information
Jbithell committed Jul 15, 2024
2 parents 283f13c + 460036f commit daf05fc
Show file tree
Hide file tree
Showing 7 changed files with 310 additions and 12 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion .github/workflows/dependabot-automerge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
steps:
- name: Dependabot metadata
id: metadata
uses: dependabot/fetch-metadata@v1.1.1
uses: dependabot/fetch-metadata@v2.1.0
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
- name: Enable auto-merge for Dependabot PRs
Expand Down
69 changes: 66 additions & 3 deletions gatsby-node.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,81 @@
import TidalData from "./data/tides.json";
import path from "path";
import { TidesJson_PDFObject } from "./src/types";
import { CreatePagesArgs } from "gatsby";
import { TidesJson_PDFObject, TidesJson_ScheduleObject } from "./src/types";
import { BuildArgs, CreatePagesArgs } from "gatsby";
import fs from "fs";
import ical, { ICalEventBusyStatus, ICalEventClass } from "ical-generator";
import { DateTime } from "luxon";

export const createPages = async function ({
actions,
graphql,
}: CreatePagesArgs) {
TidalData.pdfs.forEach((pdf: TidesJson_PDFObject) => {
actions.createPage({
path: "tide-tables/" + pdf.url,
path: "/tide-tables/" + pdf.url,
component: path.resolve(`./src/components/templates/TideTablePage.tsx`),
context: { pdf },
defer: false,
});
actions.createRedirect({
fromPath: "/tide-tables/" + pdf.url.replace("/", "-"),
toPath: "/tide-tables/" + pdf.url,
});
actions.createRedirect({
fromPath: "/tide-tables/" + pdf.url.replace("/", "-") + ".pdf",
toPath: "/tide-tables/" + pdf.url + ".pdf",
});
});

// Legacy page
actions.createRedirect({
fromPath: "/historical-tables",
toPath: "/tide-tables",
});
};

export const onPostBootstrap = function ({ reporter }: BuildArgs) {
reporter.info(`Generating iCal file for tide times`);
const cal = ical();
cal.timezone("Europe/London");
cal.name("Porthmadog Tide Times");
cal.description(
"Tide times for Porthmadog, Borth-y-gest, Morfa Bychan and Black Rock Sands from Port-Tides.com"
);
const today = new Date();
today.setHours(0, 0, 0, 0);
const nextYear = new Date(today);
nextYear.setDate(today.getDate() + 365);
TidalData.schedule
.filter((tideDay: TidesJson_ScheduleObject) => {
let date = new Date(tideDay.date);
return date >= today && date <= nextYear;
})
.forEach((day: TidesJson_ScheduleObject) =>
day.groups.forEach((tide) => {
cal.createEvent({
start: DateTime.fromSQL(day.date + " " + tide.time).toJSDate(),
end: DateTime.fromSQL(day.date + " " + tide.time)
.plus({ minutes: 30 })
.toJSDate(),
summary: `High Tide Porthmadog - ${tide.height}m`,
description: {
plain: "Powered by port-tides.com",
html: `More details at <a href="https://port-tides.com/">port-tides.com</a>`,
},
// Commented out to reduce file size
/*location: {
title: "Porthmadog",
address: "Harbwr Porthmadog, LL49 9AY, UK",
},
busystatus: ICalEventBusyStatus.FREE,
class: ICalEventClass.PUBLIC,
url: "https://port-tides.com/tide-tables",*/
});
})
);
fs.writeFileSync("public/porthmadog-tides.ical", cal.toString());
reporter.success(
`Generated iCal file for tide times at public/porthmadog-tides.ical`
);
};
58 changes: 57 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"gatsby-plugin-sitemap": "^6.13.1",
"gatsby-source-build-date": "^1.0.1",
"gatsby-source-filesystem": "^5.13.1",
"ical-generator": "^7.1.0",
"luxon": "^3.4.4",
"react": "^18.3.1",
"react-dom": "^18.3.1",
Expand Down
171 changes: 171 additions & 0 deletions src/pages/ical.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
import { Accordion, Button, Code, CopyButton, Text, rem } from "@mantine/core";
import { IconCopy, IconCopyCheck, IconHome } from "@tabler/icons-react";
import type { HeadFC, PageProps } from "gatsby";
import { Link } from "gatsby";
import * as React from "react";
import TidalData from "../../data/tides.json";
import { SEO } from "../components/SEO";
import Layout from "../components/navigation/Layout";
import { TideTablesMonthList } from "../components/tideTables/TideTablesMonthList";
import { TidesJson_PDFObject } from "../types";
import { useLocation } from "@reach/router";

const Page: React.FC<PageProps> = () => {
const { origin } = useLocation();
const iCalUrl = origin + "/porthmadog-tides.ical";
return (
<Layout
title="Tide Times in your Calendar"
headerButtons={
<Link to={"/"}>
<Button leftSection={<IconHome size={14} />} variant="light">
Homepage
</Button>
</Link>
}
>
<Accordion multiple defaultValue={["google", "apple", "outlook"]}>
<Accordion.Item value="google">
<Accordion.Control>
<Text size="xl" fw={500} mb={"xs"}>
Google Calendar
</Text>
</Accordion.Control>
<Accordion.Panel>
<Text size="lg">
<ol>
<li>
Copy the URL {iCalUrl}
<CopyButton value={iCalUrl}>
{({ copied, copy }) => (
<Button
variant="outline"
size="compact-sm"
ml="sm"
onClick={copy}
>
{copied ? (
<IconCopyCheck size={16} />
) : (
<IconCopy size={16} />
)}
</Button>
)}
</CopyButton>
</li>
<li>
<a href="https://calendar.google.com" target="_blank">
Open Google Calendar
</a>
, click the <em>+</em> above <em>My calendars</em> and choose{" "}
<em>From URL</em>.
</li>
<li>
Paste the URL into the field named <em>URL of calendar</em>{" "}
that appears and click
<em>Add calendar</em>.
</li>
<li>
After a few seconds, it should appear in your calendar. If it
does not, try reloading Google Calendar.
</li>
</ol>
</Text>
</Accordion.Panel>
</Accordion.Item>
<Accordion.Item value="apple">
<Accordion.Control>
<Text size="xl" fw={500} mb={"xs"}>
Apple Calendar
</Text>
</Accordion.Control>
<Accordion.Panel>
<Text>
<ol>
<li>
Copy the URL {iCalUrl}
<CopyButton value={iCalUrl}>
{({ copied, copy }) => (
<Button
variant="outline"
size="compact-sm"
ml="sm"
onClick={copy}
>
{copied ? (
<IconCopyCheck size={16} />
) : (
<IconCopy size={16} />
)}
</Button>
)}
</CopyButton>
</li>
<li>
In Apple Calendar, click the <em>File</em> menu and choose{" "}
<em>New Calendar Subscription…</em>.
</li>
<li>
Paste the URL into the dialog that appears and click{" "}
<em>Subscribe</em>.
</li>
<li>
A window with settings of the calendar subscription will
appear. Set <em>Auto-refresh</em> to <em>Every hour</em> to
keep your calendar up to date and click <em>OK</em>.
</li>
</ol>
</Text>
</Accordion.Panel>
</Accordion.Item>
<Accordion.Item value="outlook">
<Accordion.Control>
<Text size="xl" fw={500} mb={"xs"}>
Outlook
</Text>
</Accordion.Control>
<Accordion.Panel>
<Text>
<ol>
<li>
Copy the URL {iCalUrl}
<CopyButton value={iCalUrl}>
{({ copied, copy }) => (
<Button
variant="outline"
size="compact-sm"
ml="sm"
onClick={copy}
>
{copied ? (
<IconCopyCheck size={16} />
) : (
<IconCopy size={16} />
)}
</Button>
)}
</CopyButton>
</li>
<li>
In Outlook, click <em>Open Calendar</em> and choose{" "}
<em>From Internet…</em>.
</li>
<li>
Paste the URL into the Outlook dialog that appears and click{" "}
<em>OK</em>.
</li>
<li>
After a few seconds, Outlook will ask if the internet calendar
should be added. Click <em>Yes</em>.
</li>
</ol>
</Text>
</Accordion.Panel>
</Accordion.Item>
</Accordion>
</Layout>
);
};
export default Page;

export const Head: HeadFC = () => <SEO title="Tide Times in your calendar" />;
21 changes: 14 additions & 7 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import {
Stack,
Text,
Title,
useMatches
useMatches,
} from "@mantine/core";
import { IconArrowRight, IconTable } from "@tabler/icons-react";
import { IconArrowRight, IconCalendar, IconTable } from "@tabler/icons-react";
import { Link, type HeadFC, type PageProps } from "gatsby";
import { DateTime } from "luxon";
import * as React from "react";
Expand Down Expand Up @@ -123,11 +123,18 @@ const Page: React.FC<PageProps> = () => {
<Title order={2} size={"h3"}>
Monthly Tide Tables
</Title>
<Link to={"tide-tables/"}>
<Button rightSection={<IconArrowRight size={14} />} variant="light">
View All
</Button>
</Link>
<Group justify="flex-end">
<Link to={"ical/"}>
<Button rightSection={<IconCalendar size={14} />} variant="light">
Add to Calendar
</Button>
</Link>
<Link to={"tide-tables/"}>
<Button rightSection={<IconArrowRight size={14} />} variant="light">
View All
</Button>
</Link>
</Group>
</Group>
<TideTablesIndexList />
</Layout>
Expand Down

0 comments on commit daf05fc

Please sign in to comment.