zenn2press

Crates.iozenn2press
lib.rszenn2press
version0.1.0
sourcesrc
created_at2024-08-04 06:00:35.251097
updated_at2024-08-04 06:00:35.251097
descriptionA Rust library to convert Zenn contents to VitePress
homepage
repositoryhttps://github.com/ryohidaka/zenn2press-rs
max_upload_size
id1324741
size205,036
日高 凌 (ryohidaka)

documentation

README

zenn2press

Crates.io Version Test Suite License

zenn2press is a Rust library to convert Zenn contents to VitePress.

Features

copy_markdown_files()

Copy Markdown files from a source directory to a destination directory with options to include or exclude specific files.

copy_images()

Copy image files from a source directory to a destination directory, also with options to include or exclude specific files.

Installation

Add zenn2press to your Cargo.toml:

[dependencies]
zenn2press = "0.1.0"

Usage

CLI

Here is an example of how to use zenn2press with cli:

zenn2press --help

zenn2press \
    -s zenn \
    -c config.json \
    -d press/docs/articles \
    -m press/docs/public/images \
    -i sample-article-1

Parameters

Argument Short Long Value Name Description
src_dir -s --src-dir DIR Path of the root directory of Zenn content.
dest_dir -d --dest-dir DIR The VitePress directory path (e.g. docs/entries) where you want to place the markdown for the articles.
dest_images_dir -m --dest-images-dir DIR The VitePress directory path (e.g. public) where the image will be placed.
config_file -c --config-file FILE Configuration file path.
include -i --include <FILE> File names to include, separated by commas.
exclude -e --exclude <FILE> File names to exclude, separated by commas.

Package

Here is an example of how to use zenn2press in your project:

use zenn2press::{copy_images, copy_markdown_files};

#[tokio::main]
async fn main() {
    let src_dir = "demo/zenn/articles";
    let dest_dir = "demo/press/docs/articles";
    let config_file = Some("demo/zenn2press-config.json");
    let include = Some(vec!["sample-article-1"]);
    let exclude = None;

    // Copy markdown files from srcDir to destDir using properties
    copy_markdown_files(
        src_dir,
        dest_dir,
        config_file,
        include,
        exclude
    )
    .unwrap_or_else(|e| {
        eprintln!("Error copying markdown files: {}", e);
    });

    // Copy images from srcDir to destDir using properties
    match copy_images(
        "demo/zenn/images",
        "demo/press/docs/public/images",
        include,
        exclude
    )
    .await
    {
        Ok(_) => println!("Images copied successfully."),
        Err(e) => eprintln!("Error copying images: {}", e),
    }
}

Config file (Optional)

zenn2press-config.json

{
  "frontmatter": {
    "aside": true,
    "editLink": true,
    "footer": true,
    "lastUpdated": true,
    "layout": "doc",
    "navbar": true,
    "outline": [1, 2, 3],
    "sidebar": true,
    "titleTemplate": ":title - Custom Suffix"
  }
}

License

This project is licensed under the MIT License - see the LICENSE file for details.

Commit count: 0

cargo fmt