From 72f6c2657a87dba56c7ff4a86cf71659176e098c Mon Sep 17 00:00:00 2001 From: Dessalines Date: Wed, 2 Mar 2022 10:02:00 -0500 Subject: [PATCH] Using titles instead of indices. --- generate_translations.mjs | 15 +++++++++------ .../{1.md => 2021-08-09 - Promoting Lemmy.md} | 0 ...-09-04 - Lemmy.ml now uses open federation.md} | 0 ...-17 - Federation with Mastodon and Pleroma.md} | 0 src/shared/components/news-item.tsx | 8 +++----- src/shared/components/news.tsx | 12 +++--------- src/shared/routes.ts | 2 +- 7 files changed, 16 insertions(+), 21 deletions(-) rename src/assets/news/{1.md => 2021-08-09 - Promoting Lemmy.md} (100%) rename src/assets/news/{2.md => 2021-09-04 - Lemmy.ml now uses open federation.md} (100%) rename src/assets/news/{3.md => 2021-11-17 - Federation with Mastodon and Pleroma.md} (100%) diff --git a/generate_translations.mjs b/generate_translations.mjs index 822e32b..5d1ffd9 100644 --- a/generate_translations.mjs +++ b/generate_translations.mjs @@ -1,5 +1,6 @@ import fs from 'fs'; import fetch from 'node-fetch'; +import path from 'path'; const translationDir = "joinlemmy-translations/translations/"; const outDir = "src/shared/translations/"; @@ -24,14 +25,16 @@ try { // Write the news file try { let files = fs.readdirSync(newsDir); - let data = ""; + let data = `export const news_md = \n `; + let arr = []; for (let file of files) { - let path = `${newsDir}/${file}`; - let fNum = file.split(".")[0]; - const markdown = fs.readFileSync(path, "utf8"); - data += `export const news_md_${fNum} = \n `; - data += JSON.stringify(markdown, null, 2) + ";\n"; + let p = `${newsDir}/${file}`; + const title = path.parse(file).name; + const markdown = fs.readFileSync(p, "utf8"); + let val = { title: title, markdown: markdown }; + arr.push(val); } + data += JSON.stringify(arr, null, 2) + ";\n"; const target = outDir + "news.ts"; fs.writeFileSync(target, data); } catch (err) { diff --git a/src/assets/news/1.md b/src/assets/news/2021-08-09 - Promoting Lemmy.md similarity index 100% rename from src/assets/news/1.md rename to src/assets/news/2021-08-09 - Promoting Lemmy.md diff --git a/src/assets/news/2.md b/src/assets/news/2021-09-04 - Lemmy.ml now uses open federation.md similarity index 100% rename from src/assets/news/2.md rename to src/assets/news/2021-09-04 - Lemmy.ml now uses open federation.md diff --git a/src/assets/news/3.md b/src/assets/news/2021-11-17 - Federation with Mastodon and Pleroma.md similarity index 100% rename from src/assets/news/3.md rename to src/assets/news/2021-11-17 - Federation with Mastodon and Pleroma.md diff --git a/src/shared/components/news-item.tsx b/src/shared/components/news-item.tsx index 7f3f4c4..09e5b58 100644 --- a/src/shared/components/news-item.tsx +++ b/src/shared/components/news-item.tsx @@ -1,11 +1,9 @@ import { Component } from "inferno"; import { Helmet } from "inferno-helmet"; import { i18n } from "../i18next"; -import { news_md_1, news_md_2, news_md_3 } from "../translations/news"; +import { news_md } from "../translations/news"; import { isBrowser, mdToHtml } from "../utils"; -const newsMarkdowns = [news_md_1, news_md_2, news_md_3]; - const title = i18n.t("news"); export class NewsItem extends Component { @@ -20,8 +18,8 @@ export class NewsItem extends Component { } get markdown(): string { - let index = this.props.match.params.index; - return newsMarkdowns[index - 1]; + let title = decodeURIComponent(this.props.match.params.title); + return news_md.find(v => v.title == title).markdown; } render() { diff --git a/src/shared/components/news.tsx b/src/shared/components/news.tsx index 5bab3a6..3ca6c04 100644 --- a/src/shared/components/news.tsx +++ b/src/shared/components/news.tsx @@ -3,16 +3,10 @@ import { Link } from "inferno-router"; import { Helmet } from "inferno-helmet"; import { i18n } from "../i18next"; import { isBrowser } from "../utils"; +import { news_md } from "../translations/news"; const title = i18n.t("news"); -// Order these chronologically, recent to past -const newsLinks = [ - "2021-11-17 - Federation with Mastodon and Pleroma", - "2021-09-04 - Lemmy.ml now uses open federation", - "2021-08-09 - Promoting Lemmy", -]; - export class News extends Component { constructor(props: any, context: any) { super(props, context); @@ -36,9 +30,9 @@ export class News extends Component {
  • {i18n.t("releases")}
  • - {newsLinks.map((v, i) => ( + {news_md.reverse().map(v => (
  • - {v} + {v.title}
  • ))} diff --git a/src/shared/routes.ts b/src/shared/routes.ts index cdf12dc..610ddcf 100644 --- a/src/shared/routes.ts +++ b/src/shared/routes.ts @@ -31,7 +31,7 @@ export const routes: IRouteProps[] = [ component: Releases, }, { - path: `/news_item/:index`, + path: `/news_item/:title`, exact: true, component: NewsItem, },