Skip to content

Commit 739a9ad

Browse files
committed
Add habr translator
1 parent fd56161 commit 739a9ad

File tree

1 file changed

+189
-0
lines changed

1 file changed

+189
-0
lines changed

Habr.js

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
{
2+
"translatorID": "b4c54248-6e78-4afc-b566-45fee8cd43b7",
3+
"label": "Habr",
4+
"creator": "Ilya Zonov",
5+
"target": "https://habr.com",
6+
"minVersion": "5.0",
7+
"maxVersion": "",
8+
"priority": 100,
9+
"inRepository": true,
10+
"translatorType": 4,
11+
"browserSupport": "gcsibv",
12+
"lastUpdated": "2025-03-08 18:56:49"
13+
}
14+
15+
/*
16+
***** BEGIN LICENSE BLOCK *****
17+
18+
Copyright © 2025 YOUR_NAME <- TODO
19+
20+
This file is part of Zotero.
21+
22+
Zotero is free software: you can redistribute it and/or modify
23+
it under the terms of the GNU Affero General Public License as published by
24+
the Free Software Foundation, either version 3 of the License, or
25+
(at your option) any later version.
26+
27+
Zotero is distributed in the hope that it will be useful,
28+
but WITHOUT ANY WARRANTY; without even the implied warranty of
29+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30+
GNU Affero General Public License for more details.
31+
32+
You should have received a copy of the GNU Affero General Public License
33+
along with Zotero. If not, see <http://www.gnu.org/licenses/>.
34+
35+
***** END LICENSE BLOCK *****
36+
*/
37+
38+
39+
function detectWeb(doc, url) {
40+
if (url.match(/\/articles\/.+/)) {
41+
return 'blogPost';
42+
}
43+
44+
return false;
45+
}
46+
47+
async function doWeb(doc, url) {
48+
await scrape(doc, url);
49+
}
50+
51+
async function scrape(doc, url) {
52+
const translator = Zotero.loadTranslator('web');
53+
54+
// Embedded Metadata
55+
translator.setTranslator('951c027d-74ac-47d4-a107-9c3069ab7b48');
56+
translator.setDocument(doc);
57+
58+
translator.setHandler('itemDone', function (obj, item) {
59+
item.itemType = detectWeb(doc, url) || "webpage";
60+
item.websiteType = "Хабр";
61+
62+
// cleanup publicationTitle to switch off rewriting blogTitle
63+
item.publicationTitle = "";
64+
65+
const blogTitle = text(doc, 'a.tm-company-snippet__title > span');
66+
if (blogTitle) {
67+
item.blogTitle = `Хабр - ${blogTitle}`;
68+
}
69+
else {
70+
item.blogTitle = "Хабр";
71+
}
72+
73+
const date = attr(doc, 'meta[property="aiturec:datetime"]', 'content');
74+
item.date = ZU.strToISO(date);
75+
76+
const author = text(doc, 'div.tm-article-presenter__header span.tm-article-snippet__author a.tm-user-info__username');
77+
item.creators.push(ZU.cleanAuthor(author, "author"));
78+
79+
item.complete();
80+
});
81+
82+
translator.translate();
83+
}
84+
85+
/** BEGIN TEST CASES **/
86+
var testCases = [
87+
{
88+
"type": "web",
89+
"url": "https://habr.com/ru/articles/889174/",
90+
"items": [
91+
{
92+
"itemType": "blogPost",
93+
"title": "Lookupper: как игровой оверлей помогает изучать языки",
94+
"creators": [
95+
{
96+
"firstName": "",
97+
"lastName": "AlekseiVekhov",
98+
"creatorType": "author"
99+
}
100+
],
101+
"date": "2025-03-08",
102+
"abstractNote": "Изучение иностранных языков — это как освоение сложной игры. Вроде бы правила понятны, но как только сталкиваешься с реальным использованием, всё кажется сложнее, чем на бумаге. Нужно постоянно...",
103+
"blogTitle": "Хабр",
104+
"language": "ru",
105+
"shortTitle": "Lookupper",
106+
"url": "https://habr.com/ru/articles/889174/",
107+
"websiteType": "Хабр",
108+
"attachments": [
109+
{
110+
"title": "Snapshot",
111+
"mimeType": "text/html"
112+
}
113+
],
114+
"tags": [
115+
{
116+
"tag": "anki"
117+
},
118+
{
119+
"tag": "игры"
120+
},
121+
{
122+
"tag": "изучение английского"
123+
},
124+
{
125+
"tag": "изучение иностранных языков"
126+
},
127+
{
128+
"tag": "контекстное обучение"
129+
},
130+
{
131+
"tag": "разработка"
132+
},
133+
{
134+
"tag": "разработка приложений"
135+
}
136+
],
137+
"notes": [],
138+
"seeAlso": []
139+
}
140+
]
141+
},
142+
{
143+
"type": "web",
144+
"url": "https://habr.com/ru/companies/yandex/articles/888160/",
145+
"items": [
146+
{
147+
"itemType": "blogPost",
148+
"title": "NeurIPS: тренды, инсайты и самые интересные статьи главной ML-конференции года",
149+
"creators": [
150+
{
151+
"firstName": "",
152+
"lastName": "nstbezz",
153+
"creatorType": "author"
154+
}
155+
],
156+
"date": "2025-03-07",
157+
"abstractNote": "Привет! Меня зовут Настя Беззубцева, и я руковожу аналитикой голоса в&nbsp;Алисе. Недавно побывала на&nbsp;одной из&nbsp;крупнейших международных конференций по&nbsp;машинному обучению&nbsp;— NeurIPS...",
158+
"blogTitle": "Хабр - Яндекс",
159+
"language": "ru",
160+
"shortTitle": "NeurIPS",
161+
"url": "https://habr.com/ru/companies/yandex/articles/888160/",
162+
"websiteType": "Хабр",
163+
"attachments": [
164+
{
165+
"title": "Snapshot",
166+
"mimeType": "text/html"
167+
}
168+
],
169+
"tags": [
170+
{
171+
"tag": "LLM"
172+
},
173+
{
174+
"tag": "Taylor Swift"
175+
},
176+
{
177+
"tag": "machine learning"
178+
},
179+
{
180+
"tag": "neurips"
181+
}
182+
],
183+
"notes": [],
184+
"seeAlso": []
185+
}
186+
]
187+
}
188+
]
189+
/** END TEST CASES **/

0 commit comments

Comments
 (0)