1
0
mirror of https://github.com/GenderDysphoria/GenderDysphoria.fyi.git synced 2025-11-25 20:42:40 +00:00

Addressing issues that came up in eslint

This commit is contained in:
Jocelyn Badgley (Twipped)
2022-06-22 15:45:08 -07:00
parent 9e4868e98f
commit e229e14dca
5 changed files with 50 additions and 60 deletions

View File

@@ -5,21 +5,11 @@ const log = require('fancy-log');
const tweetparse = require('./lib/tweetparse');
const Twitter = require('twitter-lite');
const { hasOwn } = require('./lib/util');
var twemoji = require('twemoji' );
function tweetText2Html(tweet_text) {
let answer = tweet_text.split(/(\r\n|\n\r|\r|\n)+/)
.map((s) => s.trim() && '<p>' + s + '</p>')
.filter(Boolean)
.join('');
answer = twemoji.parse(answer);
return answer;
}
function applyI18N(original_tweet, twitter_i18n) {
function applyI18N (original_tweet, twitter_i18n) {
const id = original_tweet.id_str;
// Make a shallow copy
let tweet = Object.assign({}, original_tweet);
const tweet = Object.assign({}, original_tweet);
// Do we have a trnslation for this tweet?
if (twitter_i18n[id] === undefined) {
@@ -28,10 +18,10 @@ function applyI18N(original_tweet, twitter_i18n) {
delete tweet.full_text_i18n;
} else {
// If yes, add the translations
const originalLang = tweet["lang"] || "x-original";
const originalLang = tweet.lang || 'x-original';
tweet.full_text_i18n = twitter_i18n[id].full_text_i18n;
if (originalLang in tweet.full_text_i18n && tweet.full_text_i18n[originalLang] != tweet.full_text) {
log.warn("Original text not matching for tweet "+id, { expected: tweet.full_text, got: tweet.full_text_i18n[originalLang]});
if (originalLang in tweet.full_text_i18n && tweet.full_text_i18n[originalLang] !== tweet.full_text) {
log.warn('Original text not matching for tweet ' + id, { expected: tweet.full_text, got: tweet.full_text_i18n[originalLang] });
} else {
tweet.full_text_i18n[originalLang] = tweet.full_text;
}
@@ -179,7 +169,7 @@ exports.attachTweets = function (tweetids, tweets) {
}, {});
};
exports.i18n = async function() {
exports.i18n = async function () {
const [ twitterBackup, twitterCache, twitterI18N ] = await Promise.all([
fs.readJson(resolve('twitter-backup.json')),
fs.readJson(resolve('twitter-cache.json')).catch(() => ({})),
@@ -189,15 +179,15 @@ exports.i18n = async function() {
const twitterCacheBkp = JSON.stringify(twitterCache, null, 2);
// Make sure no translation is forgotten
for (const id in twitterI18N) {
if (id in twitterBackup) {
for (const id of Object.keys(twitterI18N)) {
if (twitterBackup[id]) {
twitterCache[id] = applyI18N(twitterBackup[id], twitterI18N);
twitterCache[id] = tweetparse(twitterCache[id]);
}
}
const twitterCacheJson = JSON.stringify(twitterCache, null, 2);
if (twitterCacheBkp != twitterCacheJson) {
if (twitterCacheBkp !== twitterCacheJson) {
await fs.writeFile(resolve('twitter-cache.json'), twitterCacheJson);
}
}
};