Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"@types/unist": "^2.0.6",
"@webdoky/yari-ports": "^3.5.0",
"acorn-import-assertions": "^1.8.0",
"classnames": "~2.3.2",
"cyrillic-to-translit-js": "^3.2.1",
"github-slugger": "^1.4.0",
"gray-matter": "^4.0.3",
Expand Down
9 changes: 9 additions & 0 deletions src/registry/utils/is-url-ukrainian.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const UKRAINIAN_URL_REGEXPS = [
/^https?:\/\/uk\.javascript\.info/,
/^https?:\/\/uk\.wikipedia\.org/,
/^https?:\/\/\w+\.google\.com\/.+\?hl=uk/,
];

export default function isUrlUkrainian(url: string): boolean {
return UKRAINIAN_URL_REGEXPS.some((regexp) => regexp.test(url));
}
19 changes: 13 additions & 6 deletions src/registry/utils/plugins/external-links.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import classNames from 'classnames';
import { visit } from 'unist-util-visit';
import { parse } from 'space-separated-tokens';
import isAbsoluteUrl from 'is-absolute-url';
import { extend } from 'lodash-es';

import isUrlUkrainian from '../is-url-ukrainian';

const defaultTarget = '_blank';
const defaultRel = ['nofollow', 'noopener', 'noreferrer'];
const defaultProtocols = ['http', 'https'];
Expand Down Expand Up @@ -47,12 +50,16 @@ const externalLinks = (options: Options = {}) => {
node.properties.target = target || defaultTarget;
}

if (className) {
node.properties.className =
(node.properties.className
? `${node.properties.className} `
: '') + className;
}
const isUkrainian = isUrlUkrainian(url);

node.properties.className = classNames(
node.properties.className,
className,
{
'wd-foreign': !isUkrainian,
Comment thread
undead404 marked this conversation as resolved.
Outdated
'wd-ukrainian': isUkrainian,
Comment thread
undead404 marked this conversation as resolved.
Outdated
},
);

if (rel !== false) {
node.properties.rel = (rel || defaultRel).toString().concat();
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1981,6 +1981,11 @@ cidr-regex@^3.1.1:
dependencies:
ip-regex "^4.1.0"

classnames@~2.3.2:
version "2.3.2"
resolved "https://registry.yarnpkg.com/classnames/-/classnames-2.3.2.tgz#351d813bf0137fcc6a76a16b88208d2560a0d924"
integrity sha512-CSbhY4cFEJRe6/GQzIk5qXZ4Jeg5pcsP7b5peFSDpffpe1cqjASH/n9UTjBwOp6XpMSTwQ8Za2K5V02ueA7Tmw==

clean-stack@^2.0.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/clean-stack/-/clean-stack-2.2.0.tgz#ee8472dbb129e727b31e8a10a427dee9dfe4008b"
Expand Down