Add recommended instances

This commit is contained in:
Felix Ableitner 2022-03-30 14:56:52 +02:00
parent fcd45027c4
commit 7427bd6f51
3 changed files with 73 additions and 49 deletions

View file

@ -1,11 +1,13 @@
import fs from 'fs'; import fs from 'fs';
import fetch from 'node-fetch'; import fetch from 'node-fetch';
import path from 'path'; import path from 'path';
import { exit } from 'process';
const translationDir = "joinlemmy-translations/translations/"; const translationDir = "joinlemmy-translations/translations/";
const outDir = "src/shared/translations/"; const outDir = "src/shared/translations/";
const translatorsJsonFile = "lemmy-translations/translators.json"; const translatorsJsonFile = "lemmy-translations/translators.json";
const statsFile = "lemmy-instance-stats/stats.json"; const statsFile = "lemmy-instance-stats/stats.json";
const recommendationsFile = "lemmy-instance-stats/recommended-instances.csv";
const newsDir = "src/assets/news"; const newsDir = "src/assets/news";
const releasesLocation = "https://raw.githubusercontent.com/LemmyNet/lemmy/main/RELEASES.md"; const releasesLocation = "https://raw.githubusercontent.com/LemmyNet/lemmy/main/RELEASES.md";
@ -13,15 +15,32 @@ fs.mkdirSync(outDir, { recursive: true });
// Write the stats file // Write the stats file
try { try {
const json = JSON.parse(fs.readFileSync(statsFile, "utf8")); const stats = JSON.parse(fs.readFileSync(statsFile, "utf8"));
const recommended_domains = fs.readFileSync(recommendationsFile, "utf8").split(',');
const recommended = stats.instance_details.filter(i =>
recommended_domains.includes(i.domain)
);
const remaining = stats.instance_details.filter(i =>
!recommended_domains.includes(i.domain)
);
let stats2 = {
crawled_instances: stats.crawled_instances,
total_users: stats.total_users,
recommended: recommended,
remaining: remaining,
}
let data = `export const instance_stats = \n `; let data = `export const instance_stats = \n `;
data += JSON.stringify(json, null, 2) + ";"; data += JSON.stringify(stats2, null, 2) + ";";
const target = outDir + "instance_stats.ts"; const target = outDir + "instance_stats.ts";
fs.writeFileSync(target, data); fs.writeFileSync(target, data);
} catch (err) { } catch (err) {
console.error(err); console.error(err);
} }
exit();
// Write the news file // Write the news file
try { try {
let files = fs.readdirSync(newsDir); let files = fs.readdirSync(newsDir);

@ -1 +1 @@
Subproject commit 9d7a7f751aa43cbbf062244523d448b94a81e7ee Subproject commit 226c7930eca4fafb0aefc7121d9a15add7ea5d60

View file

@ -11,6 +11,22 @@ export class Instances extends Component<any, any> {
super(props, context); super(props, context);
} }
render() {
return (
<div class="container">
<Helmet title={title}>
<meta property={"title"} content={title} />
</Helmet>
<h1 class="is-marginless">{i18n.t("lemmy_servers")}</h1>
{this.header()}
<br />
<br />
{this.render_list("Recommended", instance_stats.recommended)}
{this.render_list("Popular", instance_stats.remaining)}
</div>
);
}
header() { header() {
return ( return (
<i> <i>
@ -22,56 +38,45 @@ export class Instances extends Component<any, any> {
); );
} }
render() { render_list(header: string, instances: any[]) {
let instances = instance_stats.instance_details;
return ( return (
<div> <div>
<Helmet title={title}> <h2>{header}</h2>
<meta property={"title"} content={title} /> <div class="row">
</Helmet> {instances.map(i => (
<div class="container"> <div class="card col-6">
<h1 class="is-marginless">{i18n.t("lemmy_servers")}</h1> <header>
{this.header()} <div class="row">
<br /> <h4 class="col">{i.domain}</h4>
<br /> <h4 class="col text-right">
<p>{i18n.t("choose_and_join")}</p> <i>
{numToSI(i.users_active_month)} {i18n.t("users")} /{" "}
<div class="row"> {i18n.t("month")}
{instances.map(i => ( </i>
<div class="card col-6"> </h4>
<header>
<div class="row">
<h4 class="col">{i.domain}</h4>
<h4 class="col text-right">
<i>
{numToSI(i.users_active_month)} {i18n.t("users")} /{" "}
{i18n.t("month")}
</i>
</h4>
</div>
</header>
<div class="is-center">
<img
class="join-banner"
src={i.icon || "/static/assets/images/lemmy.svg"}
/>
</div> </div>
<br /> </header>
<p class="join-desc">{i.description}</p> <div class="is-center">
<footer> <img
{i.require_application ? ( class="join-banner"
<a class="button primary" href={`https://${i.domain}`}> src={i.icon || "/static/assets/images/lemmy.svg"}
{i18n.t("apply_to_join")} />
</a>
) : (
<a class="button primary" href={`https://${i.domain}`}>
{i18n.t("join")}
</a>
)}
</footer>
</div> </div>
))} <br />
</div> <p class="join-desc">{i.description}</p>
<footer>
{i.require_application ? (
<a class="button primary" href={`https://${i.domain}`}>
{i18n.t("apply_to_join")}
</a>
) : (
<a class="button primary" href={`https://${i.domain}`}>
{i18n.t("join")}
</a>
)}
</footer>
</div>
))}
</div> </div>
</div> </div>
); );