-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
310 additions
and
12 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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` | ||
); | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" />; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters