Skip to content

Instantly share code, notes, and snippets.

@gucheen
Created August 15, 2023 13:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gucheen/5bd696c06d37c22fc4fe2036b40c295e to your computer and use it in GitHub Desktop.
Save gucheen/5bd696c06d37c22fc4fe2036b40c295e to your computer and use it in GitHub Desktop.
convert pinboard json data to standard netscape html bookmarks
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