-
Notifications
You must be signed in to change notification settings - Fork 770
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New translator for LinkedIn post pages. #3373
base: master
Are you sure you want to change the base?
Changes from all commits
a38ad6b
626c6e4
e6857f9
42c391a
accded0
2b9c474
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
{ | ||
"translatorID": "797eb77d-9596-450e-a589-1621dc34a057", | ||
"label": "LinkedIn", | ||
"creator": "Liz Lawley", | ||
"target": "^https://www\\.linkedin\\.com/posts/", | ||
"minVersion": "3.0", | ||
"maxVersion": "", | ||
"priority": 100, | ||
"inRepository": true, | ||
"translatorType": 4, | ||
"browserSupport": "gcsibv", | ||
"lastUpdated": "2024-10-13 16:36:16" | ||
} | ||
|
||
// NOTE: This translator will only work if you are *not* logged into LinkedIn. Logged-in versions of the page do not include the necessary metadata. If you are logged into LinkedIn, you can open a private or incognito window to use the translator. // | ||
|
||
function detectWeb(doc, url) { | ||
if (url.includes('/posts/')) { | ||
return "forumPost"; | ||
} | ||
return false; | ||
} | ||
|
||
function doWeb(doc, url) { | ||
scrape(doc, url); | ||
} | ||
|
||
function scrape(doc, url) { | ||
var newItem = new Zotero.Item("forumPost"); | ||
|
||
// Extract and clean up the title (first 20 words of the description) | ||
var rawDescription = ZU.xpathText(doc, "//meta[@property='og:description']/@content"); | ||
if (rawDescription) { | ||
mamamusings marked this conversation as resolved.
Show resolved
Hide resolved
|
||
var words = ZU.unescapeHTML(rawDescription).split(/\s+/); | ||
var title = words.slice(0, 20).join(' '); | ||
newItem.title = title + (words.length > 20 ? '...' : ''); | ||
} | ||
|
||
newItem.url = url.replace(/[#?].*$/, ''); | ||
|
||
// Extract author name from page title | ||
var pageTitle = ZU.xpathText(doc, "//title"); | ||
if (pageTitle) { | ||
var titleParts = pageTitle.split(' on '); | ||
if (titleParts.length > 1) { | ||
var authorName = titleParts[0].trim(); | ||
newItem.creators.push(ZU.cleanAuthor(authorName, "author")); | ||
} | ||
} | ||
|
||
// Extract date from JSON-LD | ||
var jsonLD = doc.querySelector('script[type="application/ld+json"]'); | ||
if (jsonLD) { | ||
try { | ||
var data = JSON.parse(jsonLD.textContent); | ||
if (data.datePublished) { | ||
newItem.date = ZU.strToISO(data.datePublished); | ||
} | ||
} | ||
catch (e) { | ||
Zotero.debug("Failed to parse JSON-LD: " + e); | ||
} | ||
} | ||
|
||
newItem.forumTitle = "LinkedIn"; | ||
newItem.postType = "LinkedIn Post"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know if we really need this - it's a |
||
newItem.websiteType = "Social Media"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto - I don't think this is necessary for a citation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wasn't sure about this. LinkedIn posts are in kind of a gray area between forum posts and blog posts. |
||
|
||
newItem.attachments.push({ | ||
title: "Snapshot", | ||
document: doc | ||
}); | ||
newItem.complete(); | ||
} | ||
|
||
/** BEGIN TEST CASES **/ | ||
var testCases = [ | ||
{ | ||
"type": "web", | ||
"url": "https://www.linkedin.com/posts/emollick_we-hope-that-such-tools-may-help-us-to-gain-activity-7249843496746979328-7tXt/?utm_source=share&utm_medium=member_desktop", | ||
"items": [ | ||
{ | ||
"itemType": "forumPost", | ||
"title": "\"We hope that such tools may help us to gain novel insight into the psychology of an understudied pool of...", | ||
"creators": [ | ||
{ | ||
"firstName": "Ethan", | ||
"lastName": "Mollick", | ||
"creatorType": "author" | ||
} | ||
], | ||
"date": "2024-10-09", | ||
"forumTitle": "LinkedIn", | ||
"postType": "LinkedIn Post", | ||
"url": "https://www.linkedin.com/posts/emollick_we-hope-that-such-tools-may-help-us-to-gain-activity-7249843496746979328-7tXt/?utm_source=share&utm_medium=member_desktop", | ||
"attachments": [ | ||
{ | ||
"title": "Snapshot", | ||
"mimeType": "text/html" | ||
} | ||
], | ||
"tags": [], | ||
"notes": [], | ||
"seeAlso": [] | ||
} | ||
] | ||
} | ||
] | ||
/** END TEST CASES **/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
scrape()
only works whenscript[type="application/ld+json"]
exists, we should check that here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added