Created
August 15, 2023 13:34
-
-
Save gucheen/5bd696c06d37c22fc4fe2036b40c295e to your computer and use it in GitHub Desktop.
convert pinboard json data to standard netscape html bookmarks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import fs from 'fs' | |
const rawFile = 'bookmarks.json' | |
const outputHTML = 'bookmarks.html' | |
const pinboardData = JSON.parse(fs.readFileSync(rawFile).toString()) | |
fs.writeFileSync(outputHTML, `<!DOCTYPE NETSCAPE-Bookmark-file-1> | |
<!--This is an automatically generated file. | |
It will be read and overwritten. | |
Do Not Edit! --> | |
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8"> | |
<Title>Bookmarks</Title> | |
<H1>Bookmarks</H1> | |
<DL> | |
`) | |
for (const item of pinboardData) { | |
const url = item.href | |
const date = new Date(item.time).valueOf() | |
const tags = item.tags.split(' ').join(',') | |
const title = item.description | |
const description = item.extended | |
const dd = `<DT><A HREF="${url}" ADD_DATE="${date}" TAGS="${tags}">${title}</A> | |
` | |
fs.appendFileSync(outputHTML, dd) | |
if (description) { | |
fs.appendFileSync(outputHTML, `<DD>${description}\n`) | |
} | |
} | |
fs.appendFileSync(outputHTML, '</DL>\n') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment