Firefox bookmarks to ActivityStreams 2.0

This is a script to convert a Firefox bookmarks export to ActivityStreams 2.0 so you can import it into your own website or ActivityPub system.

You can export Firefox bookmarks as HTML, but if you choose 'backup' instead of export, you get JSON. So this is just a couple of PHP functions which parse that JSON, pull out the useful information, and shuffle it into AS2 objects.

It turns each bookmark URL into an as:Article with a name. These Articles are the object of an as:Add Activity. The target of the Add you can configure yourself to be the URL of your bookmarks collection. The date from the Firefox data I use as the published date in the Add, and I also auto-generate a summary. The script generates a unique new URL for every Add using the pattern /yyyy/mm/unique-id. You can of course configure this to match your Activity URLs template. This is what one looks like:

{
    "@context": "https://www.w3.org/ns/activitystreams#",
    "type": "Add",
    "id": "https://rhiaro.co.uk/2016/06/58749e0b104c8",
    "published": "2016-06-13T15:32:44+00:00",
    "summary": "Amy added 'Web memex' to Bookmarks",
    "object": {
        "id": "http://webmemex.org/",
        "type": "Article",
        "name": "Web memex"
    },
    "target": "https://rhiaro.co.uk/bookmarks/",
    "actor": "https://rhiaro.co.uk/#me"
}

It also generates the contents of your bookmarks collection:

{
    "@context": "https://www.w3.org/ns/activitystreams#",
    "id": "https://rhiaro.co.uk/bookmarks/",
    "type": "Collection",
    "name": "Bookmarks",
    "items": [
        "https://rhiaro.co.uk/2016/06/58749f535ac7b",
        "https://rhiaro.co.uk/2017/01/58749f535ce3e",
        "https://rhiaro.co.uk/2016/04/58749f535cee0",
        "https://rhiaro.co.uk/2016/09/58749f535d068",
        ...
    ]
}

The truth is, until yesterday most of my Firefox bookmarks are accidents; side effects of me accidentally clicking bookmark or mashing keyboard shortcuts. Then csarven shared his bookmarks export with me so I needed to do something to get a handle on all this data.

The script includes a form which lists all of the bookmarks with checkboxes beside them once it has parsed the Firefox data. This lets you choose which ones to include in the final output. When you confirm your selection, it generates a JSON list with all of the Adds inside. This lets me filter out all of the crap from accidental bookmarks... so I saved the JSON, converted it to Turtle, and dumped it in my triplestore. Voila, quadrupled the size of my bookmarks on my site.

🏷 php as2 hacking socialwg activitystreams

Post created with https://rhiaro.co.uk/sloph