Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Filter List By Tag #46

Open
krakov opened this issue Aug 8, 2021 · 1 comment
Open

Feature Request: Filter List By Tag #46

krakov opened this issue Aug 8, 2021 · 1 comment

Comments

@krakov
Copy link

krakov commented Aug 8, 2021

It would be very useful to use the list command to return only notes that match a tag.

Use case: use hackmd-cli to export some notes and batch commit them to git. Not every note should be exported, but because list returns all notes, need to download them all and then process them based on tag in YAML metadata. Listing by tag would reduce the number of exports speeding up the process.

@krakov
Copy link
Author

krakov commented Aug 8, 2021

For reference, if useful for any purpose - this is the batch commit hackmd to git script, using hackmd-cli

#!/usr/bin/env bash

## Copies any hackmd file with a git: yaml metadata into its git location
## Use it for batch commit all changes in hackmd

## Installation: 
## npm install -g @hackmd/hackmd-cli
## hackmd-cli login 

TMP_SYNC_DIR=./.hackmd_sync/

function export_all {
    mkdir -p ${TMP_SYNC_DIR}
    rm -fr ${TMP_SYNC_DIR}/*
    cd ${TMP_SYNC_DIR}
    # would be nice to filter by tag here
    hackmd-cli list --output=csv --no-header --columns=id > all_notes
    for n in $(cat all_notes) ; do
        echo "Exporting ${n}" 
        hackmd-cli export --md $n > $n
    done
}

function update_file {
    f=$1
    # any note with a "git: <location>" yaml metadata will match
    git_name=$( awk 'NR==1{ if ($1!="---") exit 1 } /git:/ { print $2 } /---/ { if (NR>1) exit }' $f )
    [[ $? == 0 ]] || return
    diff -q $f ${git_name} > /dev/null
    [[ $? == 1 ]] || return
    cp -v $f ${git_name}
    # automatically prepare the commit
    # git add ${git_name}
}

function update_all {
    for f in ${TMP_SYNC_DIR}/* ; do
        update_file $f
    done
}

export_all
update_all

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant