Import and Export of content

So, this is something I have been prototyping on the v2 branch today:

Import

There is now a generic Import: URL command that will ask you for a URL. This is a generic mechanism that plugs or Space Lua can plug into. For now there are two importers implemented:

  • A Github Gist importer, which will attempt to pull any markdown files from a Gist
  • A markdown import (for URLs that end with .md) that will simply import the content from that URL

Future importers I envision:

  • A generic importer that can take any URL and somehow converts the pulled HTML to clean markdown you can pull into your space
  • Github importer for .md on github
  • Perhaps a community.silverbullet.md importer that can pull markdown from a topic post

Every importer ought to set frontmatter for imported content leading back to the source, so that potentially (not implemented yet) in the future content can be “refreshed” from the source.

Use cases

  • A way to (more easily) distribute libraries. In v1 one we had the concept of a Library, but there was only really the Library/Core and Library/Journal one. Distribution of these required deploying a read-only SB server somewhere. Supporting this import mechanism should make distribution way easier, because people can just send you a URL to import. I think passing around Github gists will be nice and easy.
  • Read later: A way to just pull in content in your space to read later or to save for other reasons (especially useful when the generic importer for HTML will be implemented).

Export

The new Export: Page Or Selection command allows you to export a page (this replaces the old Share plug). Just like import, this mechanism is extensible. This is effectively the inverse of import.

By default there are three exporters:

  • Copy to clipboard as (expanded) markdown, so all Lua directives, queries etc. are automatically expanded and you end up with clean markdown
  • Copy to clipboard as rich text: same as the markdown one, but then also converts it to rich text (HTML) that you can e.g. paste into Google Docs or Word
  • Export as Gist: if you configure your Github token, you can export right to Github gists (to be imported by others). Once a first publish happens, frontmatter keys will be set so that future exports update the gist rather than create a new one.

In the future I’d like to port the Ghost plug to also build on this infrastructure, and of course you can imagine integrations with other tools, e.g. Wordpress.

Use cases

  • Library distribution
  • Sharing content outside your space in general (copy into google docs, some other markdown tool)

Have a play with it and tell me what you think.

These features are all 100% implemented in Space Lua are (for now) are part of the Library/Std library that is distributed with SB, you can find the implementation in your space, or here:

4 Likes

I’m thinking about a less ambitious version of that, maybe “Snippet” import which would have a list of known URL mappings to transform it into “raw” link. Motivation:

  • single HTTP request instead of waiting for round trip (although I think you need the API to discover all filenames in multifile Gist)
  • API can be heavily rate limited by unusual usage from local network (some days GitHub is unusable from my university)
  • Easier to add more similar services: Codeberg, Sourcehut, Gitlab
  • Less coupling with specific commercial product seems to be a value for self-hosting users
  • Same code with another mapping can be used to import a specific file from eg. a given branch of an online Git repo, just by copying from the address bar instead of looking for the raw button (may be small benefit, but I’ve seen people be confused when it doesn’t work)
1 Like

I do occasionally use the Ghost share plug, so it’s great to hear this type of “export” will eventually work as well.

For library distribution, I like the ideas from @janssen-io 's 🔌 External Libraries plug. Having a full github (or other) repo is a bit nicer if you want to have issues and an easier history. Gists would definitely be nice for quickly sharing something though.

Looking at Library/Std/Gist - It really reminds me of literate programming. I guess space script was already kind of the same way, but it’s still pretty neat.

1 Like