From fa6dc565cfd7afe09d8b933166e1b8d65ab366ab Mon Sep 17 00:00:00 2001 From: Dessalines Date: Wed, 16 Jun 2021 19:13:36 -0400 Subject: [PATCH] Adding autogen instance data. Fixes #29 --- .gitmodules | 4 + generate_translations.js | 14 ++ joinlemmy-translations | 2 +- lemmy-instance-stats | 1 + src/server/index.tsx | 4 +- src/shared/components/instances.tsx | 356 ++++------------------------ src/shared/utils.ts | 24 ++ update_submodules.sh | 25 ++ update_translations.sh | 10 - 9 files changed, 116 insertions(+), 324 deletions(-) create mode 160000 lemmy-instance-stats create mode 100755 update_submodules.sh delete mode 100755 update_translations.sh diff --git a/.gitmodules b/.gitmodules index 31917be..cfea1c0 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,3 +10,7 @@ path = lemmy-translations url = https://github.com/lemmynet/lemmy-translations branch = main +[submodule "lemmy-instance-stats"] + path = lemmy-instance-stats + url = https://github.com/LemmyNet/lemmy-instance-stats + branch = main diff --git a/generate_translations.js b/generate_translations.js index da1791b..5964d6f 100644 --- a/generate_translations.js +++ b/generate_translations.js @@ -3,8 +3,22 @@ const fs = require("fs"); const translationDir = "joinlemmy-translations/translations/"; const outDir = "src/shared/translations/"; const translatorsJsonFile = "lemmy-translations/translators.json"; +const statsFile = "lemmy-instance-stats/stats.json"; fs.mkdirSync(outDir, { recursive: true }); + +// Write the stats file +try { + const json = JSON.parse(fs.readFileSync(statsFile, "utf8")); + let data = `export const instance_stats = \n `; + data += JSON.stringify(json, null, 2) + ";"; + const target = outDir + "instance_stats.ts"; + fs.writeFileSync(target, data); +} catch (err) { + console.error(err); +} + +// Write the translations fs.readdir(translationDir, (_err, files) => { files.forEach(filename => { const lang = filename.split(".")[0]; diff --git a/joinlemmy-translations b/joinlemmy-translations index ebe8ea2..922a221 160000 --- a/joinlemmy-translations +++ b/joinlemmy-translations @@ -1 +1 @@ -Subproject commit ebe8ea2849178fcc5c36c769ced31dbb3c14a78f +Subproject commit 922a2219bd850bdfdf1ba6c92fccf5bd4db66f44 diff --git a/lemmy-instance-stats b/lemmy-instance-stats new file mode 160000 index 0000000..cf294ef --- /dev/null +++ b/lemmy-instance-stats @@ -0,0 +1 @@ +Subproject commit cf294efd45886f60522eb6c021813c5e2c851d9b diff --git a/src/server/index.tsx b/src/server/index.tsx index cfc3ae0..14b3325 100644 --- a/src/server/index.tsx +++ b/src/server/index.tsx @@ -76,8 +76,8 @@ server.get("/*", async (req, res) => { height: 100%; background: linear-gradient( - rgba(0, 0, 0, 0.0), - rgba(0, 0, 0, 0.0) + rgba(0, 0, 0, 0.5), + rgba(0, 0, 0, 0.5) ), url('/static/assets/images/main_img.webp'); -webkit-filter: blur(7px); diff --git a/src/shared/components/instances.tsx b/src/shared/components/instances.tsx index 60a5d86..04ad93c 100644 --- a/src/shared/components/instances.tsx +++ b/src/shared/components/instances.tsx @@ -1,336 +1,70 @@ import { Component } from "inferno"; import { Helmet } from "inferno-helmet"; import { i18n } from "../i18next"; +import { instance_stats } from "../translations/instance_stats"; +import { numToSI } from "../utils"; const title = i18n.t("join_title"); -// TODO wait until new lemmy-instances is written to refactor this - export class Instances extends Component { constructor(props: any, context: any) { super(props, context); } + + header() { + return ( + + {i18n.t("instance_totals", { + instances: numToSI(instance_stats.crawled_instances), + users: numToSI(instance_stats.total_users), + })} + + ); + } + render() { + let instances = instance_stats.instance_details; return (
-

{i18n.t("lemmy_servers")}

+

{i18n.t("lemmy_servers")}

+ {this.header()} +
+

{i18n.t("choose_and_join")}

-
-
-
-

lemmy.ml

-

- 5.9k users -

+ {instances.map(i => ( +
+
+
+

{i.domain}

+

+ + {numToSI(i.users_active_month)} {i18n.t("users")} /{" "} + {i18n.t("month")} + +

+
+
+
+
-
-
- +
+

{i.description}

+
-
-

The flagship instance of lemmy.

- -
- -
-
-
-

lemmygrad.ml

-

- 2.3k users -

-
-
-
- -
-
-

- A collection of leftist communities, for memes, learning, news, - discussion, media, or anything you like. -

- -
- -
-
-
-

lemmy.161.social

-

- 50 users -

-
-
-
- -
-
-

- An anti-authoritarian and emancipatory space for german speaking - anti-fascists. -

- -
- -
-
-
-

baraza.africa

-

- 20 users -

-
-
-
- -
-
-

- baraza is a digital public square as imagined in Bantu - philosophy, one premised on the assumption that deliberative - dialogue is a path to better societies. -

- -
- -
-
-
-

lemmy.glasgow.social

-

- 60 users -

-
-
-
- -
-
-

- A place for communities in and around Glasgow, Scotland. -

- -
- -
-
-
-

lemmy.cat

-

- 30 users -

-
-
-
- -
-
-

- A Lemmy instance for people of Catalan culture. -

- -
- -
-
-
-

lemmy.ca

-

- 11 users -

-
-
-
- -
-
-

- A Lemmy geared toward Canucks, hosted in Canuckistan, and run by - a Canuck. -

- -
- -
-
-
-

lemmy.eus

-

- 100 users -

-
-
-
- -
-
-

A Basque Lemmy instance.

- -
- -
-
-
-

sopuli.xyz

-

- 10 users -

-
-
-
- -
-
-

A general-purpose Finnish instance.

- -
- -
-
-
-

stammtisch.hallertau.social

-

- ~10 users -

-
-
-
- -
-
-

Sitz de hera, samma mehra.

- -
- -
-
-
-

szmer.info

-

- 300 users -

-
-
-
- -
-
-

A polish anti-fascist instance.

- -
- -
-
-
-

diversa.social

-

- ~ 10 users -

-
-
-
- -
-
-

- Instancia multitemática en español con un enfoque constructivo y - solidario. -

- -
+ ))}
diff --git a/src/shared/utils.ts b/src/shared/utils.ts index 7bdc44e..043a273 100644 --- a/src/shared/utils.ts +++ b/src/shared/utils.ts @@ -3,3 +3,27 @@ let DOCS_LANGUAGES = ["en", "es", "fr"]; export function getDocsLanguage(lang: string): string { return DOCS_LANGUAGES.includes(lang) ? lang : "en"; } + +export function numToSI(value: any) { + var newValue = value; + if (value >= 1000) { + var suffixes = ["", "k", "m", "b", "t"]; + var suffixNum = Math.floor(("" + value).length / 3); + var shortValue: any = ""; + for (var precision = 2; precision >= 1; precision--) { + shortValue = parseFloat( + (suffixNum != 0 + ? value / Math.pow(1000, suffixNum) + : value + ).toPrecision(precision) + ); + var dotLessShortValue = (shortValue + "").replace(/[^a-zA-Z 0-9]+/g, ""); + if (dotLessShortValue.length <= 2) { + break; + } + } + if (shortValue % 1 != 0) shortValue = shortValue.toFixed(1); + newValue = shortValue + suffixes[suffixNum]; + } + return newValue; +} diff --git a/update_submodules.sh b/update_submodules.sh new file mode 100755 index 0000000..a50f326 --- /dev/null +++ b/update_submodules.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +pushd ../joinlemmy-translations +git fetch weblate +git merge weblate/main +git push +popd + +pushd ../lemmy-translations +git fetch weblate +git merge weblate/main +git push + +popd +pushd ../lemmy-instance-stats +./update.sh +popd + +git submodule update --remote +git add joinlemmy-translations +git add lemmy-translations +git add lemmy-instance-stats + +git commit -m"Updating submodules" +git push diff --git a/update_translations.sh b/update_translations.sh deleted file mode 100755 index 2fd7b0c..0000000 --- a/update_translations.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash -pushd ../joinlemmy-translations -git fetch weblate -git merge weblate/main -git push -popd -git submodule update --remote -git add joinlemmy-translations -git commit -m"Updating joinlemmy-translations." -git push