From 1a678a4a35b116a73991e021720ec003cfba5425 Mon Sep 17 00:00:00 2001 From: Danny Wahl Date: Thu, 22 Feb 2024 18:23:49 -0700 Subject: [PATCH] add releases page --- isp-site/src/index.js | 13 ++++++ isp-site/src/routes/markdown.jsx | 5 +- isp-site/src/routes/releases.jsx | 79 ++++++++++++++++++++++++++++++++ isp-site/src/strings/releases.js | 21 +++++++++ isp-site/src/utils/releases.js | 35 ++++++++++++++ 5 files changed, 150 insertions(+), 3 deletions(-) create mode 100644 isp-site/src/routes/releases.jsx create mode 100644 isp-site/src/strings/releases.js create mode 100644 isp-site/src/utils/releases.js diff --git a/isp-site/src/index.js b/isp-site/src/index.js index ff2245bd..c18ac64d 100644 --- a/isp-site/src/index.js +++ b/isp-site/src/index.js @@ -9,6 +9,7 @@ import { InstUISettingsProvider, canvas, View } from "@instructure/ui"; import Links from "routes/links"; import MDUI from "routes/mdui"; import Markdown from "routes/markdown"; +import Releases from "routes/releases"; import ErrorPage from "routes/error"; import { ParentBrands } from "variables/brands"; import RedirectTo from "routes/redirectTo"; @@ -78,6 +79,18 @@ routes.push({ ], }); +// Release notes page +routes.push({ + path: "/releases", + element: , + children: [ + { + path: ":language", + element: , + }, + ], +}); + // All others routes.push({ path: "*", diff --git a/isp-site/src/routes/markdown.jsx b/isp-site/src/routes/markdown.jsx index 0a59de26..5a867614 100644 --- a/isp-site/src/routes/markdown.jsx +++ b/isp-site/src/routes/markdown.jsx @@ -18,7 +18,6 @@ import { Img, Table, Checkbox, - IconCloudDownloadLine, } from "@instructure/ui"; import RenderTopNavBar from "components/RenderTopNavBar"; import RenderFooter from "components/RenderFooter"; @@ -85,7 +84,7 @@ export default function Markdown({ readme }) { margin="0 auto" > -
+ -
+ diff --git a/isp-site/src/routes/releases.jsx b/isp-site/src/routes/releases.jsx new file mode 100644 index 00000000..eb76f45e --- /dev/null +++ b/isp-site/src/routes/releases.jsx @@ -0,0 +1,79 @@ +import React, { useState, useEffect } from "react"; +import ReactMarkdown from "react-markdown"; +import remarkGfm from "remark-gfm"; +import remarkGemoji from "remark-gemoji"; +import rehypeRaw from "rehype-raw"; +import global from "variables/globals"; +import { + View, + Link, + Text, + List, + Heading, + SourceCodeEditor, + Byline, + Avatar, + ToggleGroup, + Img, + Table, + Checkbox, +} from "@instructure/ui"; +import { IconRssLine } from "@instructure/ui-icons"; +import allowedElements from "variables/allowedElements"; +import mdtoui from "components/mdtoui"; +import { useParams } from "react-router-dom"; +import strings from "strings/releases"; +import { getStrings, getLang } from "utils/langs"; +import RenderFooter from "components/RenderFooter"; +import RenderTopNavBar from "components/RenderTopNavBar"; +import { printReleases } from "utils/releases"; + +export default function Releases() { + const l = getLang(useParams().language); + const s = getStrings(strings, l); + + const atom = `https://github.com/${global.owner}/${global.repo}/releases.atom`; + + const css = "hr {border: 1px solid currentColor;}"; + + const [content, setContent] = useState(`${s.loading}`); + useEffect(() => { + printReleases() + .then((text) => { + setContent(text); + }) + .catch((error) => console.error(error)); + }); + + return ( + <> + + + + + + {" "} + {s.releases} + + + + + + + , + + ); +} diff --git a/isp-site/src/strings/releases.js b/isp-site/src/strings/releases.js new file mode 100644 index 00000000..a8159bfc --- /dev/null +++ b/isp-site/src/strings/releases.js @@ -0,0 +1,21 @@ +const strings = { + releases: { + EN: "Releases", + ES_LA: "Versiones", + PT_BR: "Lançamentos", + DE: "Veröffentlichungen", + }, + loading: { + EN: "Loading...", + ES_LA: "Cargando...", + PT_BR: "Carregando...", + DE: "Wird geladen...", + }, + subscribe: { + EN: "Subscribe", + ES_LA: "Suscríbete", + PT_BR: "Inscreva-se", + DE: "Abonnieren Sie", + }, +}; +export default strings; diff --git a/isp-site/src/utils/releases.js b/isp-site/src/utils/releases.js new file mode 100644 index 00000000..a3f93969 --- /dev/null +++ b/isp-site/src/utils/releases.js @@ -0,0 +1,35 @@ +import global from "variables/globals"; + +async function getGithubReleases(owner, repo) { + const apiUrl = `${global.api}/repos/${owner}/${repo}/releases`; + try { + const response = await fetch(apiUrl, { + method: "GET", + headers: { + Accept: "application/vnd.github.v3+json", + Authorization: process.env.REACT_APP_GITHUB_TOKEN + ? `token ${process.env.REACT_APP_GITHUB_TOKEN}` + : "", + }, + }); + const data = await response.json(); + + return data.map(buildRelease).join("\r\n\r\n").slice(0, -3); + } catch (error) { + console.error(`Error: ${error.message}`); + return null; + } +} + +function buildRelease(release) { + return ` +## ${release.name}\r\n +${release.body}\r\n +---`; +} + +export async function printReleases() { + const owner = global.owner; + const repo = global.repo; + return getGithubReleases(owner, repo); +}