Using titles instead of indices.

This commit is contained in:
Dessalines 2022-03-02 10:02:00 -05:00
parent 774f7bc464
commit 72f6c2657a
7 changed files with 16 additions and 21 deletions

View file

@ -1,5 +1,6 @@
import fs from 'fs'; import fs from 'fs';
import fetch from 'node-fetch'; import fetch from 'node-fetch';
import path from 'path';
const translationDir = "joinlemmy-translations/translations/"; const translationDir = "joinlemmy-translations/translations/";
const outDir = "src/shared/translations/"; const outDir = "src/shared/translations/";
@ -24,14 +25,16 @@ try {
// Write the news file // Write the news file
try { try {
let files = fs.readdirSync(newsDir); let files = fs.readdirSync(newsDir);
let data = ""; let data = `export const news_md = \n `;
let arr = [];
for (let file of files) { for (let file of files) {
let path = `${newsDir}/${file}`; let p = `${newsDir}/${file}`;
let fNum = file.split(".")[0]; const title = path.parse(file).name;
const markdown = fs.readFileSync(path, "utf8"); const markdown = fs.readFileSync(p, "utf8");
data += `export const news_md_${fNum} = \n `; let val = { title: title, markdown: markdown };
data += JSON.stringify(markdown, null, 2) + ";\n"; arr.push(val);
} }
data += JSON.stringify(arr, null, 2) + ";\n";
const target = outDir + "news.ts"; const target = outDir + "news.ts";
fs.writeFileSync(target, data); fs.writeFileSync(target, data);
} catch (err) { } catch (err) {

View file

@ -1,11 +1,9 @@
import { Component } from "inferno"; import { Component } from "inferno";
import { Helmet } from "inferno-helmet"; import { Helmet } from "inferno-helmet";
import { i18n } from "../i18next"; 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"; import { isBrowser, mdToHtml } from "../utils";
const newsMarkdowns = [news_md_1, news_md_2, news_md_3];
const title = i18n.t("news"); const title = i18n.t("news");
export class NewsItem extends Component<any, any> { export class NewsItem extends Component<any, any> {
@ -20,8 +18,8 @@ export class NewsItem extends Component<any, any> {
} }
get markdown(): string { get markdown(): string {
let index = this.props.match.params.index; let title = decodeURIComponent(this.props.match.params.title);
return newsMarkdowns[index - 1]; return news_md.find(v => v.title == title).markdown;
} }
render() { render() {

View file

@ -3,16 +3,10 @@ import { Link } from "inferno-router";
import { Helmet } from "inferno-helmet"; import { Helmet } from "inferno-helmet";
import { i18n } from "../i18next"; import { i18n } from "../i18next";
import { isBrowser } from "../utils"; import { isBrowser } from "../utils";
import { news_md } from "../translations/news";
const title = i18n.t("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<any, any> { export class News extends Component<any, any> {
constructor(props: any, context: any) { constructor(props: any, context: any) {
super(props, context); super(props, context);
@ -36,9 +30,9 @@ export class News extends Component<any, any> {
<li> <li>
<Link to="/releases">{i18n.t("releases")}</Link> <Link to="/releases">{i18n.t("releases")}</Link>
</li> </li>
{newsLinks.map((v, i) => ( {news_md.reverse().map(v => (
<li> <li>
<Link to={`news_item/${newsLinks.length - i}`}>{v}</Link> <Link to={`news_item/${v.title}`}>{v.title}</Link>
</li> </li>
))} ))}
</ul> </ul>

View file

@ -31,7 +31,7 @@ export const routes: IRouteProps[] = [
component: Releases, component: Releases,
}, },
{ {
path: `/news_item/:index`, path: `/news_item/:title`,
exact: true, exact: true,
component: NewsItem, component: NewsItem,
}, },