Skip to content

liquid-utilities/feed-json

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

16 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Feed Json

JSON feed from collection and FrontMatter data

Byte size of Feed Json Open Issues Open Pull Requests Latest commits feed-json Demos



Requirements

This repository depends upon Jekyll which is supported by GitHub Pages, further details about setup can be found from documentation published by the Jekyll maintainers regarding GitHub Pages.

Spicificly this project utilizes the push filter that Jekyll flavored Liquid makes available to build JSON output, eg...

{% assign new_list = '' | split: ',' %}
{% assign new_list = new_list | push: 'first' %}
{% assign new_list = new_list | push: 'second' %}
{% assign new_list = new_list | push: 'third' %}

{% capture json_data %}
{
  "list": {{ new_list | jsonify }}
}
{% endcapture %}

{{ json_data }}

Quick Start

This repository encourages the use of Git Submodules to track dependencies

Bash Variables

_module_name='feed-json'
_module_https_url="https://github.com/liquid-utilities/feed-json.git"
_module_base_dir='_layouts/modules'
_module_path="${_module_base_dir}/${_module_name}"

Bash Submodule Commands

cd "<your-git-project-path>"

git checkout gh-pages
mkdir -vp "${_module_base_dir}"

git submodule add -b main\
                  --name "${_module_name}"\
                  "${_module_https_url}"\
                  "${_module_path}"

Your ReadMe File

Suggested additions for your ReadMe.md file so everyone has a good time with submodules

Clone with the following to avoid incomplete downloads


    git clone --recurse-submodules <url-for-your-project>


Update/upgrade submodules via


    git submodule update --init --merge --recursive

Commit and Push

git add .gitmodules
git add "${_module_path}"


## Add any changed files too


git commit -F- <<'EOF'
:heavy_plus_sign: Adds `liquid-utilities/feed-json#1` submodule



**Additions**


- `.gitmodules`, tracks submodules AKA Git within Git _fanciness_

- `README.md`, updates installation and updating guidance

- `_layouts/modules/feed-json`, JSON feed from collection and FrontMatter data
EOF


git push origin gh-pages

πŸŽ‰ Excellent πŸŽ‰ your project is now ready to begin unitizing code from this repository!


Usage

_config.yml (snip)

collections_dir: documentation
collections:
  example-collection:
    output: true
    permalink: /:collection/:name/

documentation/_example-collection/feed.json

layout: modules/feed-json/feed-json
title: Example Collection
description: Collection of example posts
collection_name: example-collection
collection_home: /example-collection/
date: 2021-01-01 11:12:13 -0700
permalink: /:collection/:name:output_ext

documentation/_example-collection/something-about-something.md

---
## Layout may be `default`, `post`, or `page` depending upon theme
layout: post

title: Title of Page
date: 2021-01-01 13:42:11 -0300
#date_updated:  ## Optional and formatted like `date` above

description: A description of page content
tags:
  - spam
  - flavored
  - ham
---


Content that expands on the topic of something about some thing

Expect JSON output similar to...

https://organization.github.io/project-name/example-collection/feed.json

{
  "version": "https://jsonfeed.org/version/1",
  "title": "Example Collection",
  "home_page_url": "https://<account>.github.io/<project>/",
  "feed_url": "https://<account>.github.io/<project>/example-collection/feed.json",
  "description": "Collection of example posts",
  "user_comment": "",
  "next_url": "https://<account>.github.io/<project>/other-collection/",
  "icon": "https://<account>.github.io/<project>/example-collection/icon.png",
  "favicon": "https://<account>.github.io/favicon.ico",
  "author": {
    "name": "S0AndS0",
    "url": "https://github.com/S0AndS0",
    "avatar": "https://avatars2.githubusercontent.com/u/4116150?s=460&u=c45ac68bdfbeec882ff760450de243df45700a73&v=4"
  },
  "expired": false,
  "hubs": [
    {
      "type": "",
      "url": ""
    }
  ],
  "items": [
    {
      "id": "https://<account>.github.io/<project>/posts/<name>.<ext>",
      "url": "https://<account>.github.io/<project>/posts/<name>.<ext>",
      "external_url": "https://example.com/some-applicable-reference",
      "title": "Title of Page",
      "content_html": "<html><!-- Results of rendering post layout --></html>",
      "summary": "A description of page content",
      "image": "https://<account>.github.io/<project>/assets/images/cats/funny.png",
      "banner_image": "",
      "date_published": "2021-01-01T14:13:41-14:00",
      "date_modified": "2021-01-02T14:15:00-14:00",
      "author": {
        "name": "S0AndS0",
        "url": "https://github.com/S0AndS0",
        "avatar": "https://avatars2.githubusercontent.com/u/4116150?s=400&u=c45ac68bdfbeec882ff760450de243df45700a73&v=4"
      },
      "tags": [
        "spam",
        "flavored",
        "ham"
      ],
      "attachments": [
        {
          "url": "",
          "mime_type": "",
          "title": "",
          "size_in_bytes": 99,
          "duration_in_seconds": 42
        }
      ],
      "_custom_entry": {
        "about": "",
        "explicit": false,
        "copywrite": "AGPL-3.0",
        "owner": "",
        "subtitle": ""
      },
      "content_text": "Content that expands on the topic of something about some thing"
    }
  ]
}

API

Collection FrontMatter Type Definitions

title: string

description: string?
user_comment: string?
next_url: string?
icon: string?
favicon: string?
expired: boolean?
language: string?

author: string? | dictionary?
#author:
#  name: string
#  url: string?
#  avatar: string?

authors: dictionary[]?
#authors:
#  - name: string
#    url: string?
#    avatar: string?

hubs: dictionary[]?
#hubs:
#  - type: string
#    url: string

Post FrontMatter Type Definitions

title: string

id: string?
image: string?
banner_image: string?
external_url: string?
tags: string[]?
language: string?

date: string?
#date_published: aliased to date

date_updated: string?
#date_modified: aliased to date_updated

external_url: string?

description: string?
#excerpt: aliased to description
#summary: aliased to description

author: string? | dictionary?
#author:
#  name: string
#  url: string?
#  avatar: string?

authors: dictionary[]?
#authors:
#  - name: string
#    url: string?
#    avatar: string?

attachments: dictionary[]?
#attachments:
#  - url: string
#    mime_type: string
#    title: string?
#    size_in_bytes: number?
#    durration_in_seconds: number?
  • JSON "content_html" is built from {{ post.output | jsonify }}

  • JSON "content_text" is built from {{ post.content | strip_html | jsonify }}

  • JSON "id" if undefined is built from {{ post.url | absolute_url | jsonify }}

  • JSON "date_published" is built from {{ post.date | date: date_to_xmlschema | jsonify }} when available

  • JSON "date_modified" is built from {{ post.date_updated }} or {{ post.date_modified }}, when available, and filtered the same as "date_published" value

  • JSON "summary" is built from {{ post.description }}, {{ post.summary }}, or {{ post.excerpt }}, where available and filtered similarly to {{ post.description | strip_html | jsonify }}

  • JSON "author": {"name": "", "url": "", "avatar": ""} are built from {{ page.author }}, or {{ site.author }}, when available. If YAML author is a string, then it is coerced to JSON {"author": {"name": ""}}; else if YAML author['name'] is accessible, then no coercion other than jsonify filter is used.

Notes, for JSON Feed Specification version 1.1 JSON Feed compatibility

  • JSON "authors": [{"name": "", "url": "", "avatar": ""}] are built from {{ page.authors }} or {{ site.authors }}, when available, but only if recognized as a list containing at least one object with name assigned

YAML keys not listed above map directly to JSON with minimal filtering/alteration.

This project aims to be fully compatible with JSON Feed Specification version 1; check there for further details on available key/value pares, and expected data types.


Notes

This repository may not be feature complete and/or fully functional, Pull Requests that add features or fix bugs are certainly welcomed.


If using a custom collections_dir it is advisable to move the _posts subdirectory to live there too, eg...

git mv _posts documentation/


git commit -F <<'EOF'
:dizzy: Moves posts directory to collections_dir path
EOF

For auto-discovery of feeds it is advised to include a link element within the page head, eg...

<link rel="alternate"
      title="My Feed"
      type="application/json"
      href="https://example.org/feed.json" />

Contributing

Options for contributing to feed-json and liquid-utilities


Forking

Start making a Fork of this repository to an account that you have write permissions for.

  • Add remote for fork URL. The URL syntax is git@github.com:<NAME>/<REPO>.git...
cd ~/git/hub/liquid-utilities/feed-json

git remote add fork git@github.com:<NAME>/feed-json.git
  • Commit your changes and push to your fork, eg. to fix an issue...
cd ~/git/hub/liquid-utilities/feed-json


git commit -F- <<'EOF'
:bug: Fixes #42 Issue


**Edits**


- `<SCRIPT-NAME>` script, fixes some bug reported in issue
EOF


git push fork main

Note, the -u option may be used to set fork as the default remote, eg. git push -u fork main however, this will also default the fork remote for pulling from too! Meaning that pulling updates from origin must be done explicitly, eg. git pull origin main

  • Then on GitHub submit a Pull Request through the Web-UI, the URL syntax is https://github.com/<NAME>/<REPO>/pull/new/<BRANCH>

Note; to decrease the chances of your Pull Request needing modifications before being accepted, please check the dot-github repository for detailed contributing guidelines.


Sponsor

Thanks for even considering it!

Via Liberapay you may sponsor__shields_io__liberapay on a repeating basis.

Regardless of if you're able to financially support projects such as feed-json that liquid-utilities maintains, please consider sharing projects that are useful with others, because one of the goals of maintaining Open Source repositories is to provide value to the community.


Attribution


License

JSON feed from collection and FrontMatter data
Copyright (C) 2021 S0AndS0

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, version 3 of the License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program.  If not, see <https://www.gnu.org/licenses/>.

For further details review full length version of AGPL-3.0 License.