AndySylvester
AndySylvester

@help @manton @sod I have created a new plugin which uses a JSON file that the plugin user needs to edit. How do I indicate that this file exists and provide a way to edit? Is it the includes element in plugin.json?

|
Embed
help
help

@AndySylvester @sod This is unfortunately a weak point in plug-ins right now... Not "includes", that is for including JS in the blog HTML. The user can edit the JSON by creating a custom theme and editing the plug-in's template. There should be an easier way to manage this.

|
Embed
AndySylvester
AndySylvester

@help When I look at Github repos for plugins, I see files/folders. When a Micro.blog user "installs" a plugin drawn from one of these repos, is a custom theme created as well as those files/folders copied to the user's space?

|
Embed
sod
sod

@AndySylvester @help As an alternative, you could expose the glossary data as a JSON field setting instead of a file. That way, people using your plug-in can just hit the Settings button and edit the glossary data directly, like this:

Screenshot of a text area with the label Glossary JSON and example JSON data filled in. There are two buttons: Back and Update Settings.

|
Embed
help
help

@sod @AndySylvester Using a setting is a good work-around. I'd recommend that if it's not too big of a change, until we can better support editing template files.

|
Embed
AndySylvester
AndySylvester

@sod @help how did you get this Settings UI to be created? I added a JSON field setting to a new plugin I created on my test blog, but I am not seeing any UI being generated.

|
Embed
sod
sod

@AndySylvester I added an object like this to the fields array of plugin.json:

{  
  "field": "params.glossary",  
  "label": "Glossary JSON",  
  "type": "json"  
}
|
Embed
AndySylvester
AndySylvester

@sod thanks for the example! I have updated the version number of my plugin in the repo (https://github.com/andysylvester/plugin-glossary) and added this, do you know how long it takes Micro.blog to recognize updates? cc: @help

|
Embed
sod
sod

@AndySylvester @help Up to two hours, according to this post. If you want to see your changes in real-time, you can make them via DesignEdit Custom Themes instead and commit them to git when you're happy with the result.

|
Embed
AndySylvester
AndySylvester

@sod @help I made updates to my plugin.json to add a fields array per your example, it has been 3 days now and I still do not see a "Settings" button when I load my plugin via the Plugins link, and the version still shows 1.0.0 instead of 1.0.1. How can I see the effect of the fields array if I make the changes via Design -> Edit Custom Fields?

|
Embed
sod
sod

@AndySylvester I have no insight into what's going on behind the scenes, but I do see your plugin.json file is missing a semicolon at the end of line 4. Micro.blog is probably choking on that and that's why your plug-in won't update.

When you make changes via DesignEdit Custom Themes they will be reflected right away because you're circumventing GitHub altogether. But the changes are local to your account. Other users who installed the plug-in won't see the changes you make there.

|
Embed
AndySylvester
AndySylvester

@sod thanks for pointing out that problem! I have updated my Github repo to correct that error, after making the change locally, I was able to see the Settings button on the Plugins page. I will watch to see if Micro.blog picks up the update.

|
Embed
AndySylvester
AndySylvester

@sod My next problem is how to access the glossary data exposed via the plugin.json file. This code displays all the text in the field:

{{ $linktext := $.Site.Params.glossaryData }} {{ $linktext }}

However, I have not been able to access a value given a key. Any thoughts?

|
Embed
sod
sod

@AndySylvester To convert the JSON string into a map, you can use the unmarshal function:

{{ $glossary := $.Site.Params.glossaryData | unmarshal }}

The value of the key "calculator" is "{{ $glossary.calculator }}".
|
Embed
AndySylvester
AndySylvester

@sod that works! Last issue: my shortcode has the key value as an input, should I use the range function/command to find the value that matches the key? I am looking for some example code, but have not found anything that seems to work.

|
Embed
AndySylvester
AndySylvester

@sod I think I have it worked out!

{{ $glossary := $.Site.Params.glossaryData | unmarshal }}

The value of the key "calculator" is "{{ $glossary.calculator }}".

{{ $glossaryInput := .Get 0 }}

{{ $glossaryInput }}

{{ index $glossary $glossaryInput }}

|
Embed
sod
sod

@AndySylvester 🎉

|
Embed