镜像自地址
https://gitlab.wikimedia.org/repos/mediawiki/services/zotero-translators.git
已同步 2024-06-03 03:50:18 +08:00
Medium: Update selectors and blog title extraction (#2565)
这个提交包含在:
父节点
115b9b3dbd
当前提交
611ccc3613
106
Medium.js
106
Medium.js
|
@ -2,20 +2,20 @@
|
|||
"translatorID": "6c957d6b-a554-474f-81a9-91c178fef65d",
|
||||
"label": "Medium",
|
||||
"creator": "Philipp Zumstein",
|
||||
"target": "^https?://medium\\.com",
|
||||
"target": "^https?://([^.]+\\.)?medium\\.com",
|
||||
"minVersion": "3.0",
|
||||
"maxVersion": "",
|
||||
"priority": 100,
|
||||
"inRepository": true,
|
||||
"translatorType": 4,
|
||||
"browserSupport": "gcsibv",
|
||||
"lastUpdated": "2016-12-27 14:13:31"
|
||||
"lastUpdated": "2021-07-20 01:55:16"
|
||||
}
|
||||
|
||||
/*
|
||||
***** BEGIN LICENSE BLOCK *****
|
||||
|
||||
Copyright © 2016 Philipp Zumstein
|
||||
Copyright © 2016-2021 Philipp Zumstein and Abe Jellinek
|
||||
|
||||
This file is part of Zotero.
|
||||
|
||||
|
@ -37,7 +37,7 @@
|
|||
|
||||
|
||||
function detectWeb(doc, url) {
|
||||
if (ZU.xpathText(doc, '//article[contains(@class, "postArticle")]')) {
|
||||
if (doc.querySelector('article')) {
|
||||
return "blogPost";
|
||||
} else if (getSearchResults(doc, true)) {
|
||||
return "multiple";
|
||||
|
@ -47,10 +47,11 @@ function detectWeb(doc, url) {
|
|||
function getSearchResults(doc, checkOnly) {
|
||||
var items = {};
|
||||
var found = false;
|
||||
var rows = ZU.xpath(doc, '//a[@data-post-id and h3]|//div[contains(@class, "postArticle-content")]/a[section][1]|//a[div[contains(@class, "postArticle-content")]]');
|
||||
for (var i=0; i<rows.length; i++) {
|
||||
var href = rows[i].href;
|
||||
var title = ZU.xpathText(rows[i], './/h2|.//h3');
|
||||
var rows = ZU.xpath(doc, '//a[@data-post-id and h3]|//div[contains(@class, "postArticle-content")]/a[section][1]|//a[div[contains(@class, "postArticle-content")]]|//h1//a[@rel="noopener"]');
|
||||
for (let row of rows) {
|
||||
var href = row.href;
|
||||
var title = ZU.xpathText(row, './/h2|.//h3');
|
||||
if (!title) title = row.textContent;
|
||||
if (!href || !title) continue;
|
||||
if (checkOnly) return true;
|
||||
found = true;
|
||||
|
@ -66,11 +67,7 @@ function doWeb(doc, url) {
|
|||
if (!items) {
|
||||
return true;
|
||||
}
|
||||
var articles = [];
|
||||
for (var i in items) {
|
||||
articles.push(i);
|
||||
}
|
||||
ZU.processDocuments(articles, scrape);
|
||||
ZU.processDocuments(Object.keys(items), scrape);
|
||||
});
|
||||
} else {
|
||||
scrape(doc, url);
|
||||
|
@ -81,16 +78,12 @@ function scrape(doc, url) {
|
|||
var translator = Zotero.loadTranslator('web');
|
||||
// Embedded Metadata
|
||||
translator.setTranslator('951c027d-74ac-47d4-a107-9c3069ab7b48');
|
||||
//translator.setDocument(doc);
|
||||
translator.setDocument(doc);
|
||||
|
||||
translator.setHandler('itemDone', function (obj, item) {
|
||||
|
||||
var parts = item.title.split('–');
|
||||
if (parts.length == 2) {
|
||||
item.title = parts[0];
|
||||
item.blogTitle = parts[1];
|
||||
delete item.publicationTitle;
|
||||
}
|
||||
delete item.publicationTitle;
|
||||
item.blogTitle = JSON.parse(text(doc, 'script[type="application/ld+json"]'))
|
||||
.publisher.name;
|
||||
|
||||
item.complete();
|
||||
});
|
||||
|
@ -132,14 +125,77 @@ var testCases = [
|
|||
"creatorType": "author"
|
||||
}
|
||||
],
|
||||
"date": "2014-04-22T16:02:32.005Z",
|
||||
"date": "2014-04-24T12:59:00.600Z",
|
||||
"abstractNote": "Election monitoring, new power of social media and old power of structural power",
|
||||
"blogTitle": "The Message",
|
||||
"shortTitle": "What If the Feature Is the Bug?",
|
||||
"language": "en",
|
||||
"url": "https://medium.com/message/what-if-the-feature-is-the-bug-7957d8e685c4",
|
||||
"attachments": [
|
||||
{
|
||||
"title": "Snapshot"
|
||||
"title": "Snapshot",
|
||||
"mimeType": "text/html"
|
||||
}
|
||||
],
|
||||
"tags": [],
|
||||
"notes": [],
|
||||
"seeAlso": []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "web",
|
||||
"url": "https://susanorlean.medium.com/lessons-from-an-old-dog-about-creaky-bones-and-graying-hair-9539ca79e49",
|
||||
"items": [
|
||||
{
|
||||
"itemType": "blogPost",
|
||||
"title": "Lessons from an Old Dog About Creaky Bones and Graying Hair",
|
||||
"creators": [
|
||||
{
|
||||
"firstName": "Susan",
|
||||
"lastName": "Orlean",
|
||||
"creatorType": "author"
|
||||
}
|
||||
],
|
||||
"date": "2021-07-15T16:37:56.246Z",
|
||||
"abstractNote": "The terrible truth about pets aging faster than you",
|
||||
"blogTitle": "Medium",
|
||||
"language": "en",
|
||||
"url": "https://susanorlean.medium.com/lessons-from-an-old-dog-about-creaky-bones-and-graying-hair-9539ca79e49",
|
||||
"attachments": [
|
||||
{
|
||||
"title": "Snapshot",
|
||||
"mimeType": "text/html"
|
||||
}
|
||||
],
|
||||
"tags": [],
|
||||
"notes": [],
|
||||
"seeAlso": []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "web",
|
||||
"url": "https://medium.com/illumination-curated/4-solid-facts-to-help-you-overcome-your-fear-of-selling-49be17f87255",
|
||||
"items": [
|
||||
{
|
||||
"itemType": "blogPost",
|
||||
"title": "4 Solid Facts To Help You Overcome Your Fear of Selling",
|
||||
"creators": [
|
||||
{
|
||||
"firstName": "Dennis De",
|
||||
"lastName": "Silva",
|
||||
"creatorType": "author"
|
||||
}
|
||||
],
|
||||
"date": "2021-07-19T19:18:52.609Z",
|
||||
"abstractNote": "There is still hope introverts, do not despair",
|
||||
"blogTitle": "ILLUMINATION-Curated",
|
||||
"language": "en",
|
||||
"url": "https://medium.com/illumination-curated/4-solid-facts-to-help-you-overcome-your-fear-of-selling-49be17f87255",
|
||||
"attachments": [
|
||||
{
|
||||
"title": "Snapshot",
|
||||
"mimeType": "text/html"
|
||||
}
|
||||
],
|
||||
"tags": [],
|
||||
|
@ -149,4 +205,4 @@ var testCases = [
|
|||
]
|
||||
}
|
||||
]
|
||||
/** END TEST CASES **/
|
||||
/** END TEST CASES **/
|
||||
|
|
正在加载...
在新工单中引用
屏蔽一个用户