cfenollosa / bashblog

A single Bash script to create blogs. Download, run, write, done!
1.66k stars 228 forks source link

Multi-author support using markdown metadata #156

Closed danielhjames closed 4 years ago

danielhjames commented 4 years ago

Hi, I would like to extend bashblog to read an author field from the input markdown file, only falling back to the global_author variable when an author name is not present in the input file.

The use case is when the editor of the site is the only user of bashblog, and they want to include some guest posts, so the solution using multiple .config files in #99 would not apply.

Please see https://pandoc.org/MANUAL.html#extension-yaml_metadata_block for an example syntax which could be parsed. I don't want to change the way bashblog parses the author from the generated HTML files.

If this would be useful to other bashblog users, please let me know.

danielhjames commented 4 years ago

This modification works for me. Please let me know if you would like it formatted as a pull request. And thanks for the great software @cfenollosa !

        # Parse possible tags
        elif [[ $line == "author:"* ]]; then
            author=$(echo "$line" | sed 's/author://' | sed 's/<\/*p>//')
        elif [[ -z $author ]]; then
            author=$global_author
        elif [[ $line == "<p>$template_tags_line_header"* ]]; then
            tags=$(echo "$line" | cut -d ":" -f 2- | sed -e 's/<\/p>//g' -e 's/^ *//' -e 's/ *$//' -e 's/, /,/g')
            IFS=, read -r -a array <<< "$tags"

            echo -n "<p>$template_tags_line_header " >> "$content"
            for item in "${array[@]}"; do
                echo -n "<a href='$prefix_tags$item.html'>$item</a>, "
            done | sed 's/, $/<\/p>/g' >> "$content"
        else
            echo "$line" >> "$content"
        fi
    done < "$1"

    # Create the actual html page
    create_html_page "$content" "$filename" no "$title" "$2" "$author"