mirror of
https://github.com/codex-team/codex.docs.git
synced 2025-07-23 07:09:42 +02:00
* Updated highlight.js * Update .codexdocsrc.sample remove undefined page for a fresh new install * backend rewritten in TS * test -> TS, .added dockerignore, bug fixed * Removed compiled js files, eslint codex/ts added * fixed jsdocs warning, leaving editor confirmation * use path.resolve for DB paths * db drives updated + fixed User model * redundant cleared + style fixed * explicit type fixing * fixing testing code * added body block type * compiled JS files -> dist, fixed compiling errors * fixed compiling error, re-organized ts source code * updated Dockerfile * fixed link to parent page * up nodejs version * fix package name * fix deps Co-authored-by: nvc8996 <nvc.8996@gmail.com> Co-authored-by: Taly <vitalik7tv@yandex.ru>
33 lines
800 B
TypeScript
33 lines
800 B
TypeScript
import translateString from './translation';
|
||
|
||
/**
|
||
* Convert text to URL-like string
|
||
* Example: "What is <mark>clean data</mark>" -> "what-is-clean-data"
|
||
*
|
||
* @param {string} string - source string with HTML
|
||
* @returns {string} alias-like string
|
||
*/
|
||
export default function urlify(string: string): string {
|
||
// strip tags
|
||
string = string.replace(/(<([^>]+)>)/ig, '');
|
||
|
||
// remove nbsp
|
||
string = string.replace(/ /g, ' ');
|
||
|
||
// remove all symbols except chars
|
||
string = string.replace(/[^a-zA-Z0-9А-Яа-яЁё ]/g, ' ');
|
||
|
||
// remove whitespaces
|
||
string = string.replace(/ +/g, ' ').trim();
|
||
|
||
// lowercase
|
||
string = string.toLowerCase();
|
||
|
||
// join words with hyphens
|
||
string = string.split(' ').join('-');
|
||
|
||
// translate
|
||
string = translateString(string);
|
||
|
||
return string;
|
||
}
|