mirror of
https://github.com/zyachel/quetre.git
synced 2025-04-04 13:37:39 +03:00
23 lines
691 B
JavaScript
23 lines
691 B
JavaScript
/* eslint-disable import/prefer-default-export */
|
|
import { acceptedLanguages } from './constants.js';
|
|
|
|
/**
|
|
* modifies link to be quetre-friendly.
|
|
* @param {string} url the quora url to transform. could be relative or absolute
|
|
*/
|
|
export const quetrefy = url => {
|
|
try {
|
|
const link = new URL(url);
|
|
const subdomain = link.hostname.split('.')[0];
|
|
// normal url
|
|
if (subdomain === 'www') return link.pathname;
|
|
// lang specific route
|
|
if (acceptedLanguages.includes(subdomain))
|
|
return `${link.pathname}?lang=${subdomain}`;
|
|
// must be spaces link
|
|
return `/space/${subdomain}${link.pathname}`;
|
|
} catch {
|
|
// must be a relative url
|
|
return url;
|
|
}
|
|
};
|