Added title limit setting and cleaned up README

This commit is contained in:
ThePendulum 2018-04-18 02:05:30 +02:00
parent 8649db00cd
commit 361fbb69f1
2 changed files with 15 additions and 7 deletions

View File

@ -17,27 +17,35 @@ The default configuration aims to be sensible, and the application may be used w
Path patterns dictate where and how a file will be saved. Various variables and options are available, and you may use subdirectories divided by `/`. Path patterns dictate where and how a file will be saved. Various variables and options are available, and you may use subdirectories divided by `/`.
### Variables ### Variables
#### Post
* `$postId`: The ID of the reddit post * `$postId`: The ID of the reddit post
* `$postTitle`: The title of the reddit post * `$postTitle`: The title of the reddit post
* `$postUser`: The user that submitted the post, almost always equivalent to the `--user` command line argument * `$postUser`: The user that submitted the post, almost always equivalent to the `--user` command line argument
* `$postDate`: The submission date of the reddit post, formatted by the `dateformat` configuration described below * `$postDate`: The submission date of the reddit post, formatted by the `dateformat` configuration described below
* `$postIndex`: The index of the post according to the sort method * `$postIndex`: The index of the post according to the sort method
#### Album
* `$albumId`: The ID of the media host album * `$albumId`: The ID of the media host album
* `$albumTitle`: The title of the media host album * `$albumTitle`: The title of the media host album
* `$albumDescription`: The description of the media host album * `$albumDescription`: The description of the media host album
* `$albumDate`: The submission date of the media host album, formatted by the `dateformat` configuration described below * `$albumDate`: The submission date of the media host album, formatted by the `dateformat` configuration described below
#### Item (individual image, video or text)
* `$itemId`: The ID of the individual image or video * `$itemId`: The ID of the individual image or video
* `$itemTitle`: The title of the individual image or video * `$itemTitle`: The title of the individual image or video
* `$itemDescription`: The description of the individual image or video * `$itemDescription`: The description of the individual image or video
* `$itemDate`: The submission date of the individual image or video, formatted by the `dateformat` configuration described below * `$itemDate`: The submission date of the individual image or video, formatted by the `dateformat` configuration described below
* `$itemIndex`: The index of the individual image or video in an album, offset by the `indexOffset` configuration described below * `$itemIndex`: The index of the individual image or video in an album, offset by the `indexOffset` configuration described below
* `$ext`: The extension of the file. Must typically be included, but may be omitted for self (text) posts on Unix systems * `$ext`: The extension of the medium. Must typically be included, but may be omitted for self (text) posts on Unix systems
### Date format ### `dateFormat`
Affects the representation of `$postDate`, `$albumDate` and `$itemDate` and defaults to `YYYYMMDD`. See [this documentation](https://date-fns.org/v1.29.0/docs/format) for an overview of all available tokens. Affects the representation of `$postDate`, `$albumDate` and `$itemDate` and defaults to `YYYYMMDD`. See [this documentation](https://date-fns.org/v1.29.0/docs/format) for an overview of all available tokens.
### Index offset ### `titleLimit`
Titles can sometimes be longer than you prefer your filenames to be, or even overflow the operating system's limit (255 bytes for Linux). This property cuts off titles at a fixed number of characters.
### `indexOffset`
Arrays start at 0, but as to not tire myself out debating the matter, you may offset it my any numerical value you like. Affects the `$itemIndex` variable for album items. Arrays start at 0, but as to not tire myself out debating the matter, you may offset it my any numerical value you like. Affects the `$itemIndex` variable for album items.
### Slash substitute ### `slashSubstitute`
The patterns represent Unix file paths, and a `/` therefore indicates a new directory. You may freely use directories in your paths, but titles or descriptions may contain a `/` that is not supposed to create a new directory. All instances of `/` in a variable value will be replaced with the configured slash substitute. The patterns represent Unix file paths, and a `/` therefore indicates a new directory. You may freely use directories in your paths, but titles or descriptions may contain a `/` that is not supposed to create a new directory. All instances of `/` in a variable value will be replaced with the configured slash substitute.

View File

@ -15,7 +15,7 @@ function interpolate(path, post, item) {
const vars = { const vars = {
$postId: post.id, $postId: post.id,
$postTitle: post.title, $postTitle: (post.title || '').slice(0, config.patterns.titleLength),
$postUser: post.user, $postUser: post.user,
$postDate: dateFns.format(post.datetime, dateFormat), $postDate: dateFns.format(post.datetime, dateFormat),
$postIndex: post.index + config.patterns.indexOffset $postIndex: post.index + config.patterns.indexOffset
@ -24,7 +24,7 @@ function interpolate(path, post, item) {
if(post.content.album) { if(post.content.album) {
Object.assign(vars, { Object.assign(vars, {
$albumId: post.content.album.id, $albumId: post.content.album.id,
$albumTitle: post.content.album.title, $albumTitle: (post.content.album.title || '').slice(0, config.patterns.titleLength),
$albumDescription: post.content.album.description, $albumDescription: post.content.album.description,
$albumDate: dateFns.format(post.content.album.datetime, dateFormat) $albumDate: dateFns.format(post.content.album.datetime, dateFormat)
}); });
@ -33,7 +33,7 @@ function interpolate(path, post, item) {
if(item) { if(item) {
Object.assign(vars, { Object.assign(vars, {
$itemId: item.id, $itemId: item.id,
$itemTitle: item.title, $itemTitle: (item.title || '').slice(0, config.patterns.titleLength),
$itemDescription: item.description, $itemDescription: item.description,
$itemDate: dateFns.format(item.datetime, dateFormat), $itemDate: dateFns.format(item.datetime, dateFormat),
$itemIndex: item.index + config.patterns.indexOffset, $itemIndex: item.index + config.patterns.indexOffset,