-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 parent
e182933
commit 1a678a4
Showing
5 changed files
with
150 additions
and
3 deletions.
There are no files selected for viewing
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
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,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 ( | ||
<> | ||
<RenderTopNavBar language={l} /> | ||
<View | ||
id="main" | ||
as="div" | ||
padding="medium medium xx-large" | ||
minWidth="20rem" | ||
maxWidth="59.25rem" | ||
margin="0 auto" | ||
> | ||
<Heading level="h1"> | ||
<Link href={atom}> | ||
<IconRssLine size="small" color="warning" title={s.subscribe} /> | ||
</Link>{" "} | ||
{s.releases} | ||
</Heading> | ||
<style>{css}</style> | ||
<View as="div" className="markdown"> | ||
<ReactMarkdown | ||
children={content} | ||
remarkPlugins={[remarkGfm, remarkGemoji]} | ||
rehypePlugins={[rehypeRaw]} | ||
allowedElements={allowedElements} | ||
components={mdtoui} | ||
/> | ||
</View> | ||
</View> | ||
<RenderFooter language={l} />, | ||
</> | ||
); | ||
} |
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,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; |
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,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); | ||
} |