feat: Convert types object to array

This commit is contained in:
oSumAtrIX 2023-10-29 23:16:10 +01:00
parent 47fcdd1ce3
commit 046fb6991a
No known key found for this signature in database
GPG Key ID: A9B3094ACDB604B4
3 changed files with 18 additions and 12 deletions

View File

@ -4,10 +4,10 @@ Repository to host a static API using GitHub workflows.
## How it works ## How it works
On CI trigger static files are generated and commited to the `gh-pages` branch. When CI is ran, static files are generated and commited to the `gh-pages` branch.
The file `generator.py` provides a list of static file generator classes. Each class has a name.
The static files are generated by the configuration provided in a `config.json` file in the root. The configuration file `config.json` is read which contains the configuration for the API.
The API configuration consists out of an array of objects. Each object is responsible for an API. Based on the provided pair with the key `type` in these objects a method in `generator.py` is selected to generate the API. The objects are passed to the corresponding method to consume additional key-value pairs. By specifying the name of the generator in the `types` array of the configuration, the corresponding generator will be used. The current object of the configuration is passed to the generator.
The following API configuration generates the `contributor` and `release` API for selected repositories: The following API configuration generates the `contributor` and `release` API for selected repositories:
@ -15,7 +15,7 @@ The following API configuration generates the `contributor` and `release` API fo
{ {
"api": [ "api": [
{ {
"type": "release+contributor", "types": ["release", "contributor"],
"repositories": ["user/repo"] "repositories": ["user/repo"]
} }
] ]

View File

@ -1,23 +1,31 @@
{ {
"api": [ "api": [
{ {
"type": "release+contributor", "types": [
"release+contributor"
],
"repositories": [ "repositories": [
"user/repo" "user/repo"
] ]
}, },
{ {
"type": "social", "types": [
"social"
],
"socials": { "socials": {
"website": "https://yourwebsite.com" "website": "https://yourwebsite.com"
} }
}, },
{ {
"type": "team", "types": [
"team"
],
"organization": "yourorg" "organization": "yourorg"
}, },
{ {
"type": "donation", "types": [
"donation"
],
"links": { "links": {
"liberapay": "https://liberapay.com/yourteam", "liberapay": "https://liberapay.com/yourteam",
"github": "https://github.com/sponsors/yourteam" "github": "https://github.com/sponsors/yourteam"

View File

@ -9,9 +9,7 @@ apis = config["api"]
api_provider = DefaultApiProvider() api_provider = DefaultApiProvider()
for api in apis: for api in apis:
types = api["type"].split("+") for type in api["types"]:
del api["type"] # Don't need the type for the api anymore below
for type in types:
api_type = api_provider.get(type) api_type = api_provider.get(type)
if api_type is None: if api_type is None:
continue continue