GitHub Action
Frontmatter to JSON
v0.1.0-alpha
Pre-release
This is a GitHub Action that converts the frontmatter in a file or content string to a JSON string.
content
: content as string.file
: file path as string, it's your responsibility to checkout the code or make sure the file exists.
json
: JSON string containing frontmatter.
Extract frontmatter from content
...
- id: content
name: Extract frontmatter from content
uses: TheWolfNL/frontmatter-to-json@v1
with:
content: '---\ntitle: lorem ipsum\ndescription: hello world\nnumber: 42\ndate: 2024-12-31\n---\n\n# Header 1 #\n\nParagraph 1'
- name: Output JSON
shell: bash
run: |
echo '${{ steps.content.outputs.json }}' | jq
...
Extract frontmatter from file
...
- id: file
name: Extract frontmatter from file
uses: TheWolfNL/frontmatter-to-json@v1
with:
file: 'samples/simple.md'
- name: Output JSON
shell: bash
run: |
echo '${{ steps.file.outputs.json }}' | jq
...
Use string value from frontmatter
...
- id: file
name: Extract frontmatter from file
uses: TheWolfNL/frontmatter-to-json@v1
with:
file: 'samples/simple.md'
- name: Output JSON
shell: bash
run: echo '${{ fromJson(steps.file.outputs.json).title }}' | jq
...
Use List as input for Matrix
...
jobs:
data:
runs-on: ubuntu-latest
name: Extract list from frontmatter
permissions:
contents: read # This is required for actions/checkout
outputs:
keys: ${{ fromJson(steps.file.outputs.json).keys }}
steps:
- uses: actions/checkout@v4
- id: file
name: Extract frontmatter from file
uses: TheWolfNL/frontmatter-to-json@v1
with:
file: 'samples/list.md'
keys:
runs-on: ubuntu-latest
name: Keys
needs: data
if: needs.data.outputs.keys != '[]'
strategy:
matrix:
key: ${{ fromJson(needs.data.outputs.keys) }}
steps:
- name: output
shell: bash
run: |
echo Key: '${{ matrix.key }}'
...