Skip to content

Commit 79cbb99

Browse files
committed
(habr) Add news as blogpost
1 parent a952614 commit 79cbb99

File tree

1 file changed

+50
-7
lines changed

1 file changed

+50
-7
lines changed

Habr.js

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
"translatorID": "b4c54248-6e78-4afc-b566-45fee8cd43b7",
33
"label": "Habr",
44
"creator": "Ilya Zonov",
5-
"target": "https://habr.com",
5+
"target": "^https://habr\\.com/",
66
"minVersion": "5.0",
77
"maxVersion": "",
88
"priority": 100,
99
"inRepository": true,
1010
"translatorType": 4,
1111
"browserSupport": "gcsibv",
12-
"lastUpdated": "2025-03-08 18:56:49"
12+
"lastUpdated": "2025-03-29 18:23:31"
1313
}
1414

1515
/*
@@ -37,7 +37,7 @@
3737

3838

3939
function detectWeb(doc, url) {
40-
if (url.match(/\/articles\/.+/)) {
40+
if (/\/(articles|news)\/.+/.test(url)) {
4141
return 'blogPost';
4242
}
4343

@@ -56,7 +56,6 @@ async function scrape(doc, url) {
5656
translator.setDocument(doc);
5757

5858
translator.setHandler('itemDone', function (obj, item) {
59-
item.itemType = detectWeb(doc, url) || "webpage";
6059
item.websiteType = "Хабр";
6160

6261
// cleanup publicationTitle to switch off rewriting blogTitle
@@ -73,13 +72,15 @@ async function scrape(doc, url) {
7372
const date = attr(doc, 'meta[property="aiturec:datetime"]', 'content');
7473
item.date = ZU.strToISO(date);
7574

76-
const author = text(doc, 'div.tm-article-presenter__header span.tm-article-snippet__author a.tm-user-info__username');
75+
const author = text(doc, '.tm-article-presenter__header a.tm-user-info__username');
7776
item.creators.push(ZU.cleanAuthor(author, "author"));
7877

7978
item.complete();
8079
});
8180

82-
translator.translate();
81+
const em = await translator.getTranslatorObject();
82+
em.itemType = 'blogPost';
83+
em.doWeb(doc, url);
8384
}
8485

8586
/** BEGIN TEST CASES **/
@@ -154,7 +155,7 @@ var testCases = [
154155
}
155156
],
156157
"date": "2025-03-07",
157-
"abstractNote": "Привет! Меня зовут Настя Беззубцева, и я руковожу аналитикой голоса в Алисе. Недавно побывала на одной из крупнейших международных конференций по машинному обучению — NeurIPS...",
158+
"abstractNote": "Привет! Меня зовут Настя Беззубцева, и я руковожу аналитикой голоса в Алисе. Недавно побывала на одной из крупнейших международных конференций по машинному обучению — NeurIPS...",
158159
"blogTitle": "Хабр - Яндекс",
159160
"language": "ru",
160161
"shortTitle": "NeurIPS",
@@ -184,6 +185,48 @@ var testCases = [
184185
"seeAlso": []
185186
}
186187
]
188+
},
189+
{
190+
"type": "web",
191+
"url": "https://habr.com/ru/news/840520/",
192+
"items": [
193+
{
194+
"itemType": "blogPost",
195+
"title": "Команда Rust для Linux терпит поражение в сражении с разработчиками на С, её лидер ушёл из-за «нетехнической ерунды»",
196+
"creators": [
197+
{
198+
"firstName": "",
199+
"lastName": "denis-19",
200+
"creatorType": "author"
201+
}
202+
],
203+
"date": "2024-09-03",
204+
"abstractNote": "В начале сентября 2024 года команда разработчиков проекта по внедрению Rust для ядра Linux потерпела поражение в сражении с разработчиками на С. Лидер Rust для Linux объявил, что уходит из проекта...",
205+
"blogTitle": "Хабр",
206+
"language": "ru",
207+
"url": "https://habr.com/ru/news/840520/",
208+
"websiteType": "Хабр",
209+
"attachments": [
210+
{
211+
"title": "Snapshot",
212+
"mimeType": "text/html"
213+
}
214+
],
215+
"tags": [
216+
{
217+
"tag": "Rust для Linux"
218+
},
219+
{
220+
"tag": "linux"
221+
},
222+
{
223+
"tag": "rust"
224+
}
225+
],
226+
"notes": [],
227+
"seeAlso": []
228+
}
229+
]
187230
}
188231
]
189232
/** END TEST CASES **/

0 commit comments

Comments
 (0)