mami A cross-tool document converter

Original link: https://blog.rxliuli.com/p/a657a02fccca4f788fb864f2ec8ebfa0/

A tool I am writing recently to connect different tools so that their data can be converted to each other. The main use case is multi-platform publishing and cross-application migration, such as selecting a part from joplin/obsidian notes and rendering them as blog sharing through hexo/hugo To others, in fact, now you see this blog is generated like this.

Introduction

Mami is a conversion tool that can connect different markdown-based frameworks and tools, and can convert the data of one tool to another tool, which is very helpful for cross-application migration and multi-platform release, currently known joplin/obsidian/hexo/hugo/raw , plans to support docsify/vuepress .

use

precondition

Step 1: Create a new project

The following uses pnpm as the package manager, but you can replace it with npm

Create a new directory and enter

 mkdir mami-starter && cd mami-starter

Then use your favorite package manager to initialize

 pnpm init 

Step 2: Install mami

Add @mami/cli and typescript as development dependencies of the project

 pnpm i -D @mami/cli typescript

Add some scripts to package.json

 { ... "scripts": { "gen": "mami" }, ...} 

Create your config file mami.config.ts

 import { defineConfig } from '@mami/cli'export default defineConfig({ input: [], output: [],})

then run

 $ pnpm run gen> [email protected] gen> mamistartend 

Well, nothing happens because you have no input or output plugin defined. Continue to the next step.

Step 3: Install the required plugins

Install the required plug-ins to connect the required tools. Here we use joplin => obsidian as an example

 pnpm i -D @mami/plugin-joplin @mami/plugin-obsidian

Modify your configuration file mami.config.ts

The token required by the joplin plugin here comes from the web clipper service

 import { defineConfig } from '@mami/cli'import * as joplin from '@mami/plugin-joplin'import * as obsidian from '@mami/plugin-obsidian'import path from 'path'export default defineConfig({ input: [ joplin.input({ baseUrl: 'http://127.0.0.1:41184', token: '5bcfa49330788dd68efea27a0a133d2df24df68c3fd78731eaa9914ef34811a34a782233025ed8a651677ec303de6a04e54b57a27d48898ff043fd812d8e0b31', tag: '', }), ], output: [ obsidian.output({ root: path.resolve(__dirname, 'dist'), }), ],})  

Step 4: Perform the conversion

Then you can rerun the following command

 pnpm run gen

Now you will see the converted obsidian file in dist

Example

plugin

API Documentation

Roughly speaking, plugins are divided into input and output plugins, the input plugin will return an AsyncGenerator , and the output plugin will consume it in the handle hook function.

design

Intermediate format

 { "id": "0e2510c9272449dbafe3e0f3fba12d74", "title": "Welcome to Joplin!", "content": "content body", "createAt": 1666288266591, "updateAt": 1666288266591, "path": ["Welcome! (Desktop)"], "tags": [ { "id": "04dfa5cf19e4435f9f3f09a73a7edfb2", "title": "blog" } ], "resources": [ { "id": "63b83e548b7b4adfae18544b7038b0bc", "title": "AllClients.png", "raw": "<nodejs buffer>" } ]} 

Writing plugins involves some markdown ast operations. For example, you may need to convert links in markdown. It is recommended to use mdast for processing.

motivation

If you don’t know what joplin-blog is, let me briefly introduce it: it is a cli tool for converting joplin notes into other forms of content, supporting blog/wiki frameworks such as hexo, vuepress, docsify, jeykll. ref: https://discourse.joplinapp.org/t/joplin-note-sharing-tool/13480

Why started this rewrite?

The main reason is that some frameworks are currently supported, but in fact it is still not enough. As far as I am concerned, I have now come into contact with the vitepress document generator. I plan to use it to replace vuepress, but this requires some modifications to joplin-blog. In fact, this does not not very convenient. Some people have also mentioned how to generate more customized files, such as adding additional yaml meta information to the generated markdown (ref: https://github.com/rxliuli/joplin-utils/issues/55 ), which actually It’s a bit cumbersome without extension points, the temporary solution given at that time was to use joplin-blog as a lib and insert some custom logic to do it. It was also mentioned to support hugo, but it is not shown that all are implemented in joplin-blog.

Later, we realized that a plugin system was needed to support generating arbitrary framework files, and further, we could even add input sources (eg joplin) as plugins, like pandoc, to connect different note-taking, blogging and wiki tools. One of the current attempts is mami, which intends to use markdown as an intermediate format for conversion.
At present, this project has just been created, and only supports joplin as input source and hexo/hugo/obsidian as output source, but I have already used it in my blog, reference: https://github.com/rxliuli/blog/blob /master/mami.config.ts

PS: The source of the name mami is Mami Tomoe in Puella Magi Madoka Magica, her magic is a ribbon that can connect various things and even form a musket (laughs).

This article is reproduced from: https://blog.rxliuli.com/p/a657a02fccca4f788fb864f2ec8ebfa0/
This site is for inclusion only, and the copyright belongs to the original author.