]> Untitled Git - lemmy.git/blobdiff - ui/src/utils.ts
Merge branch 'dev' into federation
[lemmy.git] / ui / src / utils.ts
index 48bd175e25a5d2933ef5db27804df5b61a161ee9..480b41c7c313a6ffcd6403456583b4ee14fe2ee9 100644 (file)
@@ -12,6 +12,7 @@ import 'moment/locale/ca';
 import 'moment/locale/fa';
 import 'moment/locale/pt-br';
 import 'moment/locale/ja';
+import 'moment/locale/ka';
 
 import {
   UserOperation,
@@ -42,8 +43,9 @@ import twemoji from 'twemoji';
 import emojiShortName from 'emoji-short-name';
 import Toastify from 'toastify-js';
 import tippy from 'tippy.js';
+import EmojiButton from '@joeattardi/emoji-button';
 
-export const repoUrl = 'https://github.com/dessalines/lemmy';
+export const repoUrl = 'https://github.com/LemmyNet/lemmy';
 export const helpGuideUrl = '/docs/about_guide.html';
 export const markdownHelpUrl = `${helpGuideUrl}#markdown-guide`;
 export const sortingHelpUrl = `${helpGuideUrl}#sorting`;
@@ -59,6 +61,7 @@ export const languages = [
   { code: 'eo', name: 'Esperanto' },
   { code: 'es', name: 'Español' },
   { code: 'de', name: 'Deutsch' },
+  { code: 'ka', name: 'ქართული ენა' },
   { code: 'fa', name: 'فارسی' },
   { code: 'ja', name: '日本語' },
   { code: 'pt_BR', name: 'Português Brasileiro' },
@@ -86,6 +89,14 @@ export const themes = [
   'i386',
 ];
 
+export const emojiPicker = new EmojiButton({
+  // Use the emojiShortName from native
+  style: 'twemoji',
+  theme: 'dark',
+  position: 'auto-start',
+  // TODO i18n
+});
+
 export function randomStr() {
   return Math.random()
     .toString(36)
@@ -107,11 +118,11 @@ export const md = new markdown_it({
   typographer: true,
 })
   .use(markdown_it_container, 'spoiler', {
-    validate: function(params: any) {
+    validate: function (params: any) {
       return params.trim().match(/^spoiler\s+(.*)$/);
     },
 
-    render: function(tokens: any, idx: any) {
+    render: function (tokens: any, idx: any) {
       var m = tokens[idx].info.trim().match(/^spoiler\s+(.*)$/);
 
       if (tokens[idx].nesting === 1) {
@@ -127,7 +138,7 @@ export const md = new markdown_it({
     defs: objectFlip(emojiShortName),
   });
 
-md.renderer.rules.emoji = function(token, idx) {
+md.renderer.rules.emoji = function (token, idx) {
   return twemoji.parse(token[idx].content);
 };
 
@@ -273,7 +284,7 @@ export function debounce(
   let timeout: any;
 
   // Calling debounce returns a new anonymous function
-  return function() {
+  return function () {
     // reference the context and args for the setTimeout function
     var context = this,
       args = arguments;
@@ -289,7 +300,7 @@ export function debounce(
     clearTimeout(timeout);
 
     // Set the new timeout
-    timeout = setTimeout(function() {
+    timeout = setTimeout(function () {
       // Inside the timeout function, clear the timeout variable
       // which will let the next execution run when in 'immediate' mode
       timeout = null;
@@ -353,6 +364,8 @@ export function getMomentLanguage(): string {
     lang = 'pt-br';
   } else if (lang.startsWith('ja')) {
     lang = 'ja';
+  } else if (lang.startsWith('ka')) {
+    lang = 'ka';
   } else {
     lang = 'en';
   }
@@ -469,8 +482,9 @@ export function setupTribute(): Tribute {
       {
         trigger: ':',
         menuItemTemplate: (item: any) => {
-          let emoji = `:${item.original.key}:`;
-          return `${item.original.val} ${emoji}`;
+          let shortName = `:${item.original.key}:`;
+          let twemojiIcon = twemoji.parse(item.original.val);
+          return `${twemojiIcon} ${shortName}`;
         },
         selectTemplate: (item: any) => {
           return `:${item.original.key}:`;
@@ -819,3 +833,15 @@ function hsl(num: number) {
 function randomHsl() {
   return `hsla(${Math.random() * 360}, 100%, 50%, 1)`;
 }
+
+export function previewLines(text: string, lines: number = 3): string {
+  // Use lines * 2 because markdown requires 2 lines
+  return text
+    .split('\n')
+    .slice(0, lines * 2)
+    .join('\n');
+}
+
+export function hostname(url: string): string {
+  return new URL(url).hostname;
+}