Skip to content

Feature Request: Filter List By Tag #46

Open

Description

@krakov

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.

Activity

  1. krakov commented on Aug 8, 2021

    @krakov
    Author

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions