mirror of
https://github.com/LemmyNet/joinlemmy-site.git
synced 2024-11-22 12:21:16 +00:00
Using titles instead of indices.
This commit is contained in:
parent
774f7bc464
commit
72f6c2657a
7 changed files with 16 additions and 21 deletions
|
@ -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) {
|
||||
|
|
|
@ -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<any, any> {
|
||||
|
@ -20,8 +18,8 @@ export class NewsItem extends Component<any, any> {
|
|||
}
|
||||
|
||||
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() {
|
||||
|
|
|
@ -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<any, any> {
|
||||
constructor(props: any, context: any) {
|
||||
super(props, context);
|
||||
|
@ -36,9 +30,9 @@ export class News extends Component<any, any> {
|
|||
<li>
|
||||
<Link to="/releases">{i18n.t("releases")}</Link>
|
||||
</li>
|
||||
{newsLinks.map((v, i) => (
|
||||
{news_md.reverse().map(v => (
|
||||
<li>
|
||||
<Link to={`news_item/${newsLinks.length - i}`}>{v}</Link>
|
||||
<Link to={`news_item/${v.title}`}>{v.title}</Link>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
|
|
|
@ -31,7 +31,7 @@ export const routes: IRouteProps[] = [
|
|||
component: Releases,
|
||||
},
|
||||
{
|
||||
path: `/news_item/:index`,
|
||||
path: `/news_item/:title`,
|
||||
exact: true,
|
||||
component: NewsItem,
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue