Skip to content

Commit 96e6426

Browse files
committed
Add Eleventy passthrough copy for translit.js and update imports
1 parent bad1771 commit 96e6426

File tree

6 files changed

+21
-70
lines changed

6 files changed

+21
-70
lines changed

.eleventy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
module.exports = function (eleventyConfig) {
22
// Copy the assets folder to the output
33
eleventyConfig.addPassthroughCopy('src/assets');
4+
eleventyConfig.addPassthroughCopy({ 'node_modules/@ce/transliteration/translit.js': 'assets/repositories/chechen-transliterator/translit.js'});
45

56
return {
67
dir: {
78
input: 'src',
89
includes: '_includes',
910
output: '_site',
1011
},
11-
pathPrefix: '/',
1212
};
1313
};

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@jsr:registry=https://npm.jsr.io

package-lock.json

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414
}
1515
},
1616
"lint-staged": {
17-
"*.js": ["prettier --write", "git add"]
17+
"*.js": [
18+
"prettier --write",
19+
"git add"
20+
]
1821
},
1922
"keywords": [],
2023
"author": "",
@@ -24,5 +27,8 @@
2427
"husky": "^9.0.11",
2528
"lint-staged": "^15.2.4",
2629
"prettier": "^3.2.5"
30+
},
31+
"dependencies": {
32+
"@ce/transliteration": "npm:@jsr/ce__transliteration@^0.1.3"
2733
}
2834
}

src/assets/repositories/chechen-transliterator/main.js

Lines changed: 2 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,4 @@
1-
// prettier-ignore
2-
const transliteration = {
3-
'а': 'a', 'аь': 'ä', 'б': 'b', 'в': 'v', 'г': 'g', 'гӏ': 'ġ', 'ц': 'c', 'цӏ': 'ċ', 'д': 'd',
4-
'е': 'e', 'ё': 'ö', 'ж': 'ƶ', 'з': 'z', 'и': 'i', 'й': 'y', 'к': 'k', 'кх': 'q', 'къ': 'q̇',
5-
'кӏ': 'k̇', 'л': 'l', 'м': 'm', 'н': 'n', 'о': 'o', 'оь': 'ö', 'п': 'p', 'пӏ': 'ṗ', 'р': 'r',
6-
'с': 's', 'т': 't', 'тӏ': 'ṫ', 'у': 'u', 'уь': 'ü', 'ф': 'f', 'х': 'x', 'хь': 'ẋ', 'хӏ': 'h',
7-
'ч': 'ç', 'чӏ': 'ç̇', 'ш': 'ş', 'щ': 'ş', 'ъ': 'ə', 'ь': '', 'э': 'e', 'ю': 'yu', 'я': 'ya',
8-
'ӏ': 'j', 'Ӏ': 'J', 'ккх': 'qq', 'ккъ': 'q̇q̇', 'юь': 'yü', 'яь': 'yä'
9-
};
10-
11-
function applyTransliteration(w) {
12-
const word = w.toLowerCase();
13-
let result = '';
14-
let i = 0;
15-
while (i < word.length) {
16-
let match = null;
17-
for (let key of [
18-
word.substring(i, i + 3),
19-
word.substring(i, i + 2),
20-
word.substring(i, i + 1),
21-
]) {
22-
if (transliteration.hasOwnProperty(key)) {
23-
if (
24-
key === 'ъ' &&
25-
i + 1 < word.length &&
26-
'еёюя'.includes(word[i + 1])
27-
) {
28-
if (i > 0 && word[i - 1] === 'к') {
29-
match = 'q̇';
30-
} else {
31-
match = ''; // 'ъ' is null before these characters unless after 'к'
32-
}
33-
} else if (key === 'е') {
34-
if (i === 0) {
35-
match = 'ye'; // 'е' at the start of the word
36-
} else if (i > 0) {
37-
if (
38-
word[i - 1] === 'ъ' &&
39-
(i < 2 || word.substring(i - 2, i) !== 'къ')
40-
) {
41-
match = 'ye'; // 'е' following 'ъ' that does not follow 'къ'
42-
} else {
43-
match = transliteration[key]; // Regular transliteration for 'е'
44-
}
45-
} else {
46-
match = transliteration[key];
47-
}
48-
} else if (key === 'н' && i === word.length - 1) {
49-
match = 'ŋ'; // 'н' at the end of the word
50-
} else {
51-
match = transliteration[key];
52-
}
53-
if (match !== null) {
54-
result += match;
55-
i += key.length;
56-
break;
57-
}
58-
}
59-
}
60-
if (match === null) {
61-
result += word[i]; // Add the character as is if no match was found
62-
i++; // Move to next character
63-
}
64-
}
65-
return result;
66-
}
1+
import * as mod from './translit.js';
672

683
function getQueryParameter(name) {
694
const urlParams = new URLSearchParams(window.location.search);
@@ -79,7 +14,7 @@ function updateQueryParameter(name, value) {
7914
function handleTransliteration() {
8015
const input = document.getElementById('transliteration-input').value;
8116
const words = input.split(' '); // Split input into words
82-
const transliteratedWords = words.map(word => applyTransliteration(word)); // Transliterate each word
17+
const transliteratedWords = words.map(word => mod.apply(word)); // Transliterate each word
8318
const output = transliteratedWords.join(' '); // Join transliterated words into a single string
8419
document.getElementById('transliteration-output').textContent = output;
8520
updateQueryParameter('text', input);

src/repositories/chechen-transliterator/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ title: Chechen Transliterator
99
<p class="mt-3">Output: <span id="transliteration-output" class="font-weight-bold"></span></p>
1010

1111
{% block extra_scripts %}
12-
<script src="/assets/repositories/chechen-transliterator/main.js"></script>
12+
<script type="module" src="/assets/repositories/chechen-transliterator/main.js"></script>
1313
{% endblock %}

0 commit comments

Comments
 (0)