question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Enhancement: Editor for data files in the Hugo 'data' folder.

See original GitHub issue

Is your feature request related to a problem? Please describe.

I have a site where there are data files (JSON) used to drive the content in tables. https://gohugo.io/templates/data-templates/

Describe the solution you’d like

I would like to describe the data model in the files like I do now with content types, and then have a UI to edit the information in the files with a GUI.

Describe alternatives you’ve considered

I can edit the plain text files by hand, but what’s the fun in that? Also, asking my editors to write JSON, YAML, TOML, etc. by hand is a bit much.

Additional context

Here is an example of a UI for the JSON content below.

image

{
  "columns": [
    "Rating",
    "Credit Score"
  ],
  "rows": [
    {
      "cells": [
        "A++",
        "750+"
      ]
    },
    {
      "cells": [
        "A+",
        "710 - 749"
      ]
    },
    {
      "cells": [
        "A",
        "680 - 709"
      ]
    },
    {
      "cells": [
        "B",
        "650 - 679 up to 80% LTV"
      ]
    },
    {
      "cells": [
        "C",
        "620 - 649 up to 70% LTV"
      ]
    }
  ]
}

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:20 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
estruyfcommented, Jan 20, 2022

i have set it for a folder and can confirm it works. Although in "frontMatter.data.types": [ a file is set in the json schema "file": "[[workspace]]/data/data-entries.yml",

Documentation for these new settings is on its way (still needs to be written before releasing v6).

  • frontMatter.data.types: This only defines the object and its fields. There is no reference to any file or folder. It has two properties: id and schema
  • frontMatter.data.files: Defines how a single file needs to be handled. It can use a schema or an ID of the data type.
  • frontMatter.data.folders: Defines that all files from a folder need to be handled the same. It can use a schema or an ID of the data type.

In your case, you better define the type via the frontMatter.data.types setting and reuse it in the file and folders setting.

1reaction
estruyfcommented, Jan 18, 2022

Recreated it with the new sample you gave, and the following schema can create your data structure:

{
  "id": "data-entries",
  "title": "Data Entries",
  "file": "[[workspace]]/data/data-entries.yml",
  "fileType": "yaml",
  "schema": {
    "type": "object",
    "properties": {
      "entries": {
        "type": "object",
        "properties": {
          "title": {
            "type": "string"
          },
          "folders": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "title": {
                  "type": "string"
                },
                "output": {
                  "type": "string"
                },
                "type": {
                  "type": "string"
                },
                "folderitems": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "title": {
                        "type": "string"
                      },
                      "url": {
                        "type": "string"
                      },
                      "output": {
                        "type": "string"
                      },
                      "type": {
                        "type": "string"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "additionalProperties": false,
    "required": [
      "entries"
    ]
  }
}

image

Read more comments on GitHub >

github_iconTop Results From Across the Web

Data Templates - Hugo
Hugo supports loading data from YAML, JSON, XML, and TOML files located in the data directory at the root of your Hugo project....
Read more >
Data Files | Forestry.io
Click “Change Template”; Choose the Front Matter Template you want and click “Done”. Futher Reading · Hugo's Data Template Docs · Jekyll's ...
Read more >
Live editing in Hugo with Bookshop | CloudCannon
Your editor can click a Visual Data Binding to open a panel, ... a specific structure within the Bookshop directory, and a schema...
Read more >
Hugo - Bejamas
Hugo supports only local flat files like markdown. If you prefer to edit content through a nice user interface, take a look at...
Read more >
Version 5.0 Beta 0 (October 2020) - Wowchemy
Save your data and plot settings using the Plotly JSON format and then ... Hugo Modules (or copy the new go.mod file to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found