npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@inkdropapp/live-export

v0.2.1

Published

A library for programmatically exoprting notes to local filesystem from Inkdrop

Downloads

21

Readme

Inkdrop Live Export

An Inkdrop module which allows you to programmatically export notes to local filesystem via the local HTTP server. It supports live export, which continuously exports notes as the changes occur.

Prerequisites

  • NodeJS >= 18
  • Inkdrop >= 5.5.1

Demo project

A simple blog:

How to use it

Enable the Inkdrop local server

Follow the instruction in the documentation.

Now you should be able to invoke the API like so:

curl http://username:password@localhost:19840/
# => {"version":"5.5.1","ok":true}

Install dev-tools plugin

It helps copy notebook IDs quickly from the context menu.

https://my.inkdrop.app/plugins/dev-tools

Then, copy a bookId of a notebook you'd like to export by right-clicking the notebook on the sidebar and select Copy Notebook ID.

Copy notebook ID

Install live-export

Suppose that you have a static website project such as a blog or a documentation, and you are in its root directory.

cd <PROJECT_ROOT>
npm i -D @inkdropapp/live-export

Example

Create a file import.mjs (It must be an ES Module). Initialize a live exporter:

import { LiveExporter, toKebabCase } from '@inkdropapp/live-export'

const liveExport = new LiveExporter({
  username: 'foo',
  password: 'bar',
  port: 19840
})

Then, start exporting like so:

const sub = await liveExport.start({
  live: true,
  bookId: '<YOUR_BOOK_ID>',
  preProcessNote: ({ note, frontmatter, tags }) => {
    frontmatter.title = note.title
    // Convert note title to kebab case (eg. "kebab-case-note-title")
    frontmatter.slug = toKebabCase(note.title)
    frontmatter.tags = tags.map(t => t.name)
  },
  pathForNote: ({ /* note, */ frontmatter }) => {
    // export only if it's public
    if (frontmatter.public) {
      return `./<PATH_TO_EXPORT_NOTES>/${frontmatter.slug}.md`
    } else return false
  },
  urlForNote: ({ frontmatter }) => {
    if (frontmatter.public) {
      return `/<URL_TO_LINK_NOTES>/${frontmatter.slug}`
    } else return false
  },
  pathForFile: ({ mdastNode, /* note, file, */ extension, frontmatter }) => {
    if (frontmatter.slug && mdastNode.alt) {
      const fn = `${frontmatter.slug}_${toKebabCase(
        mdastNode.alt
      )}${extension}`
      const res = {
        filePath: `./<PATH_TO_EXPORT_IMAGES>/${fn}`,
        url: `./<URL_TO_LINK_IMAGES>/${fn}`
      }
      // If the `alt` attribute of the image is 'thumbnail', use it as a hero image
      if (mdastNode.alt === 'thumbnail') {
        frontmatter.heroImage = res.filePath
      }
      return res
    } else return false
  },
  postProcessNote: ({ md }) => {
    // Remove the thumbnail image from the Markdown body
    const md2 = md.replace(/\!\[thumbnail\]\(.*\)\n/, '')
    return md2
  }
})

If you would like to cancel/stop exporting:

sub.stop()

And run it:

node --experimental-vm-modules import.mjs

start() parameters

bookId: string

The notebook ID to export. Required.

live?: boolean

If true, it continuously exports as you change notes in Inkdrop. If false, it performs one-time export.

false by default.

pathForNote(data)

Generate a path to export the specified note

  • data.note: Note - The note to export
  • data.frontmatter: Record<string, any> - The YAML frontmatter of the note
  • data.tags: An array of Tag - The tags of the note
  • Returns: string | false | Promise<...> - A destination path to export. If it returns false, the note will be skipped exporting.

urlForNote(data)

Generate a URL for the specified note. It is necessary to link from the note to another note.

  • data.note: Note - The note to export
  • data.frontmatter: Record<string, any> - The YAML frontmatter of the note
  • data.tags: An array of Tag - The tags of the note
  • Returns: string | false | Promise<...> - A url/relative path. If it returns false, the note will be skipped processing.

pathForFile(data)

Generate a path and URL to export the specified image file.

  • data.note: Note - The note data
  • data.mdastNode: Image - The mdast node of the image
  • data.file: File - The attached image file data to export
  • data.extension: string - The file extension of the image (e.g., '.jpg', '.png')
  • data.frontmatter: Record<string, any> - The YAML frontmatter of the note
  • data.tags: An array of Tag - The tags of the note
  • Returns: { filePath: string; url: string } | false | Promise<...> - A destination file path to export and url to link. If it returns false, the image will be skipped exporting.

preProcessNote(data)

Pre-process the specified note. It is useful to update the frontmatter information based on the note metadata.

  • data.note: Note - The note data
  • data.frontmatter: Record<string, any> - The YAML frontmatter of the note
  • data.tags: An array of Tag - The tags of the note
  • data.mdast: Root - The mdast root node of the note
  • Returns: any | Promise<any>

postProcessNote(data)

Post-process the specified note right before writing the note to a file. It is useful to tweak the Markdown data (e.g., deleting unnecessary lines).

  • data.md: string - The Markdown data
  • data.frontmatter: Record<string, any> - The YAML frontmatter of the note
  • data.tags: An array of Tag - The tags of the note
  • Returns: string | Promise<string> - Returns the processed Markdown string

Debugging

Set environment variable DEBUG='inkdrop:export:info,inkdrop:export:error' to enable console outputs

FAQ

How can I see the access logs of the local server?

Run the app with a --enable-logging flag. See the documentation for more detail.

Can I import the notes back to Inkdrop?

No. As it transforms the notes for your projects, they are no longer compatible with Inkdrop.