0.1.2 • Published 9 months ago

@cesarlai/picgo-plugin-filename-format v0.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

picgo-plugin-filename-format

A picgo plugin to format filename by your setting.

You can use this plugin with Typora to format file name before upload.

Installation

# Mac
cd ~/.picgo
npm i --save picgo-plugin-filename-format@npm:@cesarlai/picgo-plugin-filename-format
# Windows
cd C:\\Users\\<Your User Name>\\.picgo
npm i --save picgo-plugin-filename-format@npm:@cesarlai/picgo-plugin-filename-format

Usage

After install this plugin, you should edit .picgo/config.json like this

{
  "picBed": {
    "uploader": "aliyun",
    "aliyun": {
      // ...
    },
    "current": "aliyun"
  },
  "picgoPlugins": {
    // use this plugin
    "picgo-plugin-filename-format": true
  },
  // config how to format your file name
  "picgo-plugin-filename-format": {
    // format type (e.g. origin/hash/uuid/timestamp/time)
    "format": "hash",
    // format options
    "options": {
      "type": "sha256",
      "length": 16
    }
  }
}

Now you can run picgo u <file path> or upload file by Typora, and the file name will be formatted according to your setting before upload.

If you upload an image call demo.png

// format: origin 
https://cloud.com/images/demo.png

// format: hash 
https://cloud.com/images/F797b746fa17615e.png

// format: uuid 
https://cloud.com/images/b117132a-1df4-47dd-b861-a4a2eb687703.png

// format: timestamp 
https://cloud.com/images/1705770275093.png

// format: time 
https://cloud.com/images/2024-01-01/demo.png // nameFormat: origin
https://cloud.com/images/2024-01-01/F797b746fa17615e.png // nameFormat: hash
https://cloud.com/images/2024-01-01/1705770275093.png // nameFormat: timestamp

API

Basic Configuration

Field NameField TypeDescription
formatstringFormat type (default origin) e.g. origin, uuid, hash, time, timestamp
optionsobjectFormat options, every format type has different options

Origin Options

Format type origin need't to set options.

UUID Options

Format type uuid need't to set options.

Hash Options

Field NameField TypeDescription
typestringHash algorithm that supported by OpenSSL (default sha256) e.g. sha256, sha512, etc
lengthnumberThe hash output length (default 32) e.g. 8, 16, 32, etc

Example

{
  "format": "hash",
  "options": {
    "type": "sha256",
    "length": 16
  }
}

Timestamp Options

Field NameField TypeDescription
lengthnumberThe timestamp output length (default 13) e.g. 10, 13

Example

{
  "format": "timestamp",
  "options": {
    "length": 13
  }
}

Time Options

Field NameField TypeDescription
timeFormatstringTime prefix format template that supported by dayjs (default YYYY-MM-DD)
nameFormatstringFile name format type, supporting above types (default origin) e.g. origin, uuid, hash, timestamp
nameOptionsobjectFile name format options

Example

{
  "format": "time",
  "options": {
    "timeFormat": "YYYYMMDDHHmmss",
    "nameFormat": "hash",
    "nameOptions": {
      "length": 16
    }
  }
}
0.1.2

9 months ago

0.1.1

1 year ago

0.1.0

1 year ago