diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..892a875b --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,31 @@ +name: ci +on: + workflow_dispatch: +# push: + branches: + - main +permissions: + contents: write +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Configure Git Credentials + run: | + git config user.name github-actions[bot] + git config user.email 41898282+github-actions[bot]@users.noreply.github.com + - uses: actions/setup-python@v4 + with: + python-version: 3.x + - run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV + - uses: actions/cache@v3 + with: + key: mkdocs-material-${{ env.cache_id }} + path: .cache + restore-keys: | + mkdocs-material- + - run: chmod ug+x scripts/genMkdocsSite.sh + - run: scripts/genMkdocsSite.sh + - run: pip install mkdocs-material + - run: mkdocs gh-deploy --force \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..c5a994d4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,24 @@ +# Dependencies +/node_modules + +# Production +/build + +# Generated files +.docusaurus +.cache-loader + +# Misc +.DS_Store +.env.local +.env.development.local +.env.test.local +.env.production.local + +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +/tmp +.yarn +/site diff --git a/OCABundles/schema/README.md b/OCABundles/schema/README.md new file mode 100644 index 00000000..72bbb65e --- /dev/null +++ b/OCABundles/schema/README.md @@ -0,0 +1 @@ +# Credential OCA Bundles diff --git a/OCABundles/schema/bcgov-digital-trust/LCRB/README.md b/OCABundles/schema/bcgov-digital-trust/LCRB/README.md new file mode 100644 index 00000000..e52a32fd --- /dev/null +++ b/OCABundles/schema/bcgov-digital-trust/LCRB/README.md @@ -0,0 +1 @@ +# LCRB diff --git a/OCABundles/schema/bcgov-digital-trust/README.md b/OCABundles/schema/bcgov-digital-trust/README.md new file mode 100644 index 00000000..247356fa --- /dev/null +++ b/OCABundles/schema/bcgov-digital-trust/README.md @@ -0,0 +1 @@ +# BC Gov diff --git a/OCABundles/schema/qc_anig_demo/README.md b/OCABundles/schema/qc_anig_demo/README.md new file mode 100644 index 00000000..f60b4fed --- /dev/null +++ b/OCABundles/schema/qc_anig_demo/README.md @@ -0,0 +1 @@ +# MCN, Government of Quebec diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 00000000..a5f49a0f --- /dev/null +++ b/docs/README.md @@ -0,0 +1,230 @@ +# Aries OCA Bundles + +This GitHub repository is for hosting published Overlays Capture Architecture +(OCA) Bundles to be used by Hyperledger Aries agents (issuers, holders and +verifiers). The repository includes a [lightweight governance](GOVERNANCE.md) +process for ensuring those contributing to the repository are the "authority" +over the OCA Bundle they are submitting/updating, and that what they are +submitting is, in fact, an OCA Bundle for a published AnonCreds Schema and/or +Credential Definition. + +The OCA Bundles should follow the rules for [OCA for Aries](https://github.com/swcurran/aries-rfcs/tree/oca4aries/features/0755-oca-for-aries) OCA Bundles, +including the [OCA for Aries Style Guide](https://github.com/swcurran/aries-rfcs/tree/966b3e83870178d66a85db194a21739f0f807bef/features/0756-oca-for-aries-style-guide). Each OCA Bundle must be accompanied +by some metadata about the credential, such as on what ledger the credential +schema and definition (CredDef) reside, and may be accompanied by the full OCA +Source data--Excel and JSON files. We have some tools in the repo for +converting OCA Source to the Bundle to make it easier for contributors. + +Currently, the repository assumes that the OCA Bundles are for [Hyperledger +AnonCreds Verifiable Credentials](https://hyperledger.org/use/anoncreds). We +expect that other formats, such as W3C Verifiable Credentials Data Model +Standard JSON-LD credentials will eventually also be supported. + +## Previewing And Designing OCA Bundles + +When it comes to creating an OCA Bundle previewing the branding can be +done with the [OCA +Explorer](https://bcgov.github.io/aries-oca-bundles/) + +### What is OCA Explorer + +Overlays Capture Architecture (OCA) allows issuers to control the look +of a credentials in a users wallet. In addition, OCA makes supporting +multiple languages such as French and English easy. + +### Using OCA Explorer + +To design and preview an OCA Bundle, head over to the [OCA +Explorer](https://bcgov.github.io/aries-oca-bundles/) and either +select an existing bundle in the repository or upload one of your own. + +![Select OCA Bundle](./docs/assets/upload_OCA_bundle.PNG) + +Once you have selected or uploaded an OCA Bundle, a preview will +display. If configured in the bundler there may be the option to +choose from a variety of available languages using radio buttons based +on the [multilingual +overlay](https://github.com/swcurran/aries-rfcs/tree/oca4aries/features/0755-oca-for-aries#oca-specification-overlays). + +The remaining fields displayed are derived from the [branding +overlay](https://github.com/swcurran/aries-rfcs/tree/oca4aries/features/0755-oca-for-aries#aries-specific-branding-overlay), +which can be customized according to your preferences. You can easily +fill in these fields and download the branding overlay by clicking on +the `DOWNLOAD BRANDING OVERLAY` button. + +Take a look at the screenshot below for an idea of what the branding +customization interface looks like: + +![Customizing OCA Branding](./docs/assets/OCA_bundle_preview.PNG) + +Don't hesitate to experiment and create an OCA Bundle that best suits +your needs! + +## Locations of OCA Bundles + +OCA Bundles in this repository are found in the [OCABundles](./OCABundles/) +folder in this repository. The folder structure within `OCABundles` is as follows +with OCABundle JSON files in the `` folders. The folders can be nested +arbitrarily deeply, and the `` folder **MUST** have an `OCABundle.json` +file that is the OCA Bundle itself, plus a `README.md` file that contains +the structured information about the Bundle. More on that below. + +``` +OCABundles + ┗ schema + ┃ ┣ + ┃ ┃ ┣ + ┃ ┃ ┣ + ┃ ┃ ┃ ┣ + ┃ ┃ ┃ ┗ + ┃ ┗ + ┃ ┃ ┣ + ┃ ┃ ┗ + ``` + +## Contributing an OCA Bundle + +To contribute an OCA Bundle, create a pull request that adds the necessary files +for the Aries for OCA: + +* In the OCABundles `schema` folder, if needed, create a new +``. Those folders are for organizing the credentials +and the folder naming is up to the submitter. +* Create additional folders below, named for the schema or credential + type being added. As needed, nest the folders as make sense. At leaf + must be the `` folder. +* Within the `` folder, add the following files, as appropriate: + * README.md: **MUST** be present and **MUST** contain the information outlined + below in the [README File Content](#readme-file-content) section of this document. + * OCABundle.json: **MUST** be present and **MUST** contain the OCA Bundle + for the schema or credential definition. + * \.xlsx: (optional) An Excel OCA Source file for the OCA Bundle. + * branding.json: (optional) A JSON file containing the source content for + the OCA for Aries Branding overlay. + * testdata.csv: (optional) A CSV file containing one or more sample data + records. + * Other files: (optional) Other files related to the OCA Bundle, such as the + images used in the branding.json file. + +The pull request will be reviewed according to the [lightweight governance](GOVERNANCE.md) +process and merged (or not) into the repository. + +### README File Content + +The README.md file for the OCA Bundle **MUST** be present and **MUST** include +begin with the information shown and described below. The formatting requirements +are in place because the file is processed by a script that generates two lists +of all of the identifiers (`schemaId`s and `credDefId`s) and the OCA Bundles +to which they are associated with. The lists are in the files `ocbundles.json` +and `ocabundleslist.json` in the root folder of the repository. + +```text +# + +<DESCRIPTION> + +- Publishing Organization: <ORGANIZATION> +- Primary Contact Email Address: <CONTACT EMAIL ADDRESS> + +## Identifiers + +| Identifier | Location | URL | +| ------------------------------------------ | --------- | ----------- | +| <SCHEMA ID or CRED DEF ID> | <LEDGER> | <URL> | + +## Authorization + +The following are the GitHub IDs of those authorized to make substantive updates to the OCA Bundle. + +| OCA Bundle Contributors | GitHub ID | Email Address | +| ----------------------- | ----------- | ------------------------ | +| <NAME> | <GITHUB ID> | <EMAIL ADDRESS> | + +``` + +Everything not in `<>`s must be exactly as specified above (with one +exception--see below). Everything in `<>`s **MUST** be populated as described +below. + +The two markdown tables **MAY** have multiple lines. Multiple lines in the +`Identifiers` table indicates that the same OCA Bundle is used for each of the +objects identified in the first column. Multiple lines in the `Authorization` +table is recommended so that multiple members of the submitters team may update +the OCA Bundle. + +- `<TITLE>` **MUST** be the name of the credential type. No other line in the + file can have a single `#` prefix. +- `<DESCRIPTION>` is extracted for display by tools for processing this +repository (such as the [OCA Explorer]) and should describe the type of +credential to which the OCA Bundle applies. +- `<ORGANIZATION>` is extracted for display by tools for processing this +repository (such as the [OCA Explorer]) and is the name of the organization +that submitted the OCA Bundle. +- `<CONTACT EMAIL ADDRESS>` is an email address for the primary contact +for the OCA Bundle. The address may for a person, or better, a group +contact withing the `<ORGANIZATION>`. +- `<SCHEMA ID or CRED DEF ID>` are identifiers for objects to which the +OCA Bundles applies. There can be multiple lines in the table, each with +a different identifier. +- `<LEDGER>` is optional. It identifies the ledger on which the object +identified by the object resides. It should be in the form +<network>[:<instance>] as defined in the [did-indy specification for +`namespace`](https://hyperledger.github.io/indy-did-method/#indy-did-method-identifiers) +-- e.g., `candy:dev` or `sovrin`. The value is useful when the `<SCHEMA ID or +CRED DEF ID>` is unqualified (such as with legacy Indy identifiers) such that +the precise location of the object is not known. +- `<URL>` is optional and is a plain (non-Markdown) link to a ledger browser + instance of the object, such as to a transaction on + [https://indyscan.io](https://indyscan.io) or + [https://candyscan.idlab.org/](https://candyscan.idlab.org/) +- `<NAME>' is the name of a person authorized to update the OCA Bundle and +related data. There may be multiple rows in the markdown table to name multiple +people. +- `<GITHUB ID>` is the GitHub ID of the named person. +- `<EMAIL ADDRESS>` is the email address of the named person + +[OCA Explorer]: https://bcgov.github.io/aries-oca-bundles/ + +The `<CONTACT EMAIL ADDRESS>` and the Authorization table are to ensure that +once the OCA Bundle is submitted, there are contacts available to answer +questions about, and to submit updates to, the OCA Bundle. + +The contents of the `Authorization` section (following the `## Authorization` line) may be replaced +with the following to avoid repeating the same contents in every OCA Bundle `README.md` file: + +`The Authorization table for this OCA Bundle is in [this file](<path-to-another-OCABundle-folder/README.md).` + +## Agent Processing + +The following are the steps for processing the OCA Bundle by an Aries Holder or Verifier. + +An Aries holder (wallet) or verifier agent **MUST** be pre-configured with the +URL (\<URL> in the following) for accessing raw files in the main branch of the +`OCABundles` folder in this repository, e.g. +`https://raw.githubusercontent.com/bcgov/aries-oca-bundles/main`. + +On receipt of an AnonCreds Credential Definition ID (credDefid), the Aries agent **SHOULD** do the following: + +- Load the JSON file `<URL>/ocabundles.json`. + - This may be done at Aries wallet/agent initialization time and the contents + cached. The wallet/agent may reload the file from time to time to get + updates to the contents. +- Scan the list of identifiers for the credDefId in the loaded JSON data structure. + - If found, use the corresponding `path` item value to load the OCA Bundle for the credential at (`<URL>/<path>`). +- Scan the list of identifiers for the schemaId referenced in the Credential Definition in the loaded JSON data structure. + - If found, use the corresponding `path` item value to load the OCA Bundle for the credential at (`<URL>/<path>`). +- If not found, proceed without an OCA Bundle for the credential. + +The wallet/agent may want to cache a loaded OCA Bundle. + +### Processing Notes + +* A given Aries agent **MAY** want to pre-load OCA Bundles for Schemas or +Credential Definitions for all of the identifiers in the `ocabundles.json` file. +From time-to-time, such agents may want to reload the Bundles in case they have +been updated in the repository. + +## Creating the OCA Bundle JSON + +See the instructions for creating an OCA Bundle JSON file from Excel and JSON source +in the file [OCABundleCreation.md](OCABundleCreation.md) in the root of this repository. diff --git a/CONTRIBUTING.md b/docs/contributing/CONTRIBUTING.md similarity index 100% rename from CONTRIBUTING.md rename to docs/contributing/CONTRIBUTING.md diff --git a/OCABundleCreation.md b/docs/contributing/OCABundleCreation.md similarity index 97% rename from OCABundleCreation.md rename to docs/contributing/OCABundleCreation.md index a2586bfa..16eedb3b 100644 --- a/OCABundleCreation.md +++ b/docs/contributing/OCABundleCreation.md @@ -38,8 +38,7 @@ use a converter to create the OCA Bundle JSON from the two sources. [sample OCA for Aries OCA Bundle]: https://github.com/swcurran/aries-rfcs/tree/oca4aries/features/0755-oca-for-aries/OCA4AriesBundle.json [example here]: https://github.com/swcurran/aries-rfcs/blob/oca4aries/features/0755-oca-for-aries/OCA4Aries.xlsx -[OCA Template]: https://github.com/THCLab/oca-parser-xls/blob/main/templates/template.xlsx -[OCA Excel Parser Repository]: https://github.com/THCLab/oca-parser-xls +[OCA Template]: https://github.com/THCLab/oca-parser-xls/blob//templates/template.xlsx [Human Colossus Foundation]: https://humancolossus.foundation/ [Aries Specific Dates in the OCA Formats Overlay]: https://github.com/swcurran/aries-rfcs/tree/oca4aries/features/0755-oca-for-aries#aries-specific-dates-in-the-oca-format-overlay @@ -145,7 +144,7 @@ Developers will likely have the `jq` (JSON Query) command line utility already i Installing the OCA Excel Parser is a little more involved, as you need Rust installed on your machine. Here are the steps: -- Clone a local copy of the [OCA Excel Parser Repository]. +- Clone a local copy of the OCA Excel Parser repository. - If you don't have Rust installed on your machine, following the [Rust Installation Instructions], including installing all necessary dependencies. - Follow the instructions in the repository README.md to build the parser. Currently it is just to execute `cargo build`. - Copy the resulting executable to a directory on your PATH, e.g., `cp target/debug/parser ~/bin/` diff --git a/GOVERNANCE.md b/docs/governance/GOVERNANCE.md similarity index 100% rename from GOVERNANCE.md rename to docs/governance/GOVERNANCE.md diff --git a/docs/oca-explorer/README.md b/docs/oca-explorer/README.md new file mode 100644 index 00000000..bcf4ad43 --- /dev/null +++ b/docs/oca-explorer/README.md @@ -0,0 +1 @@ +<iframe src="https://bcgov.github.io/aries-oca-explorer" width="100%" height="800" frameborder="0"></iframe> \ No newline at end of file diff --git a/mkdocs.yml b/mkdocs.yml new file mode 100644 index 00000000..fde8791f --- /dev/null +++ b/mkdocs.yml @@ -0,0 +1,108 @@ +site_name: Aries OCA Bundles +repo_name: bcgov/aries-oca-bundles +repo_url: https://github.com/bcgov/aries-oca-bundles +theme: + name: material + custom_dir: overrides + logo: https://raw.githubusercontent.com/hyperledger/aries-acapy-docs/main/assets/Hyperledger_Aries_Logo_White.png + favicon: https://aries.js.org/img/aries-logo.png + icon: + repo: fontawesome/brands/github + palette: + # Palette toggle for light mode + - media: "(prefers-color-scheme: light)" + scheme: default + toggle: + icon: material/brightness-7 + name: Switch to dark mode + # Palette toggle for dark mode + - media: "(prefers-color-scheme: dark)" + scheme: slate + toggle: + icon: material/brightness-4 + name: Switch to light mode + features: + - content.code.copy + - navigation.expand + - navigation.footer + - navigation.instant + - navigation.tabs + - navigation.tabs.sticky + - navigation.top + - navigation.tracking + - toc.follow +# - toc.integrate +markdown_extensions: + - abbr + - admonition + - attr_list + - def_list + - footnotes + - md_in_html + - toc: + permalink: true + toc_depth: 3 + - pymdownx.arithmatex: + generic: true + - pymdownx.betterem: + smart_enable: all + - pymdownx.caret + - pymdownx.details + - pymdownx.emoji: + emoji_generator: !!python/name:materialx.emoji.to_svg + emoji_index: !!python/name:materialx.emoji.twemoji + - pymdownx.highlight: + anchor_linenums: true + - pymdownx.inlinehilite + - pymdownx.keys + - pymdownx.magiclink: + repo_url_shorthand: true + user: squidfunk + repo: mkdocs-material + - pymdownx.mark + - pymdownx.smartsymbols + - pymdownx.superfences: + custom_fences: + - name: mermaid + class: mermaid + format: !!python/name:pymdownx.superfences.fence_code_format + - pymdownx.tabbed: + alternate_style: true + - pymdownx.tasklist: + custom_checkbox: true + - pymdownx.tilde +plugins: + - search +nav: +- Welcome: + - Read Me: README.md +- Governance: + - Repository Governance: governance/GOVERNANCE.md + - License: governance/LICENSE.md + - Maintainers: governance/MAINTAINERS.md +- Adding Your OCA Bundle: + - Contributing: contributing/CONTRIBUTING.md + - Creating OCA Bundles: contributing/OCABundleCreation.md +- OCA Explorer: + - OCA Explorer: oca-explorer/README.md +- OCA Bundles: + - Credential OCA Bundles: + - BC Gov: + - OCABundles/schema/bcgov-digital-trust/business-card/README.md + - OCABundles/schema/bcgov-digital-trust/business-card-showcase/README.md + - LCRB: + - OCABundles/schema/bcgov-digital-trust/LCRB/selling-it-right-showcase/README.md + - OCABundles/schema/bcgov-digital-trust/LCRB/serving-it-right-showcase/README.md + - OCABundles/schema/bcgov-digital-trust/LCRB/special-event-server-showcase/README.md + - OCABundles/schema/bcgov-digital-trust/member-card/README.md + - OCABundles/schema/bcgov-digital-trust/member-card-showcase/README.md + - BC Mines Act Permit: + - OCABundles/schema/bcgov-digital-trust/mines-act-permit/0.3/README.md + - OCABundles/schema/bcgov-digital-trust/mines-act-permit/1.1.1/README.md + - OCABundles/schema/bcgov-digital-trust/person/README.md + - OCABundles/schema/bcgov-digital-trust/person-showcase/README.md + - OCABundles/schema/bcgov-digital-trust/pilot/README.md + - OCABundles/schema/bcgov-digital-trust/student-card/README.md + - OCABundles/schema/bcgov-digital-trust/unverified-person/README.md + - MCN, Government of Quebec: + - OCABundles/schema/qc_anig_demo/Attestation_numérique_didentité_gouvernemental/README.md diff --git a/scripts/genMkdocsSite.sh b/scripts/genMkdocsSite.sh new file mode 100755 index 00000000..fc24ffd2 --- /dev/null +++ b/scripts/genMkdocsSite.sh @@ -0,0 +1,65 @@ +#!/bin/bash + +if [ "$1" == "clean" ]; then + # Clean out the updates made in the docs folder by this script + rm docs/governance/MAINTAINERS.md + rm docs/governance/LICENSE.md + rm -rf docs/OCABundles + rm docs/ocabundles.json + rm docs/ocabundleslist.json + exit 0 +fi + + +# This script is for generating the documentation structure from documents in the Aries OCA Bundles repository. +# This script is intended to run from a GitHub Action as part of updating the gh-pages branch and publishing the website +# The process is: +# - Delete the existing content of the /docs folder in this repo, leaving only `docs/assets` +# - Generate the Mkdocs navigation for the site and put it in place of the current mkdocs YML +# - For each folder that will be in the /docs folder of this rep0: +# - For each file the is to be in the folder within the /docs folder +# - Either directly copy, or copy with edits applied the source file to the /docs folder +# - Edits are needed to "fix" the links to work when the file is in the new place in the repo +# See the edits below for the types of changes needed. Usually, they are to change absolute +# links in the markdown documents to relative links in this folder, as well as to handle changes +# in where the docs are placed. +# +# To find broken links: +# - Run mkdocs locally and click on links and images that result in 404s +# - Once you publish the docs, run a "broken link finder" tool to find others +# To find missing documentation files +# - Scan the /tmp folder for all .md files and see if you have them in the /docs folder +# - a script to compare the list of .md files in /tmp and /docs is planned + +# Have to be sure we're in the root folder of the repository +thisDir=${PWD} +if [ ! -d "OCABundles" ]; then + echo ERROR: There is no OCABundles folder. This script must be run from the root of the repository. + echo ERROR: Current directory is: ${thisDir} + show_help + exit 1 +fi + +# echo Building pages for the Aries OCA Bundles website + +# Copy MD files that need to be in the root folder to the doc folder +cp MAINTAINERS.md docs/governance/ +cp LICENSE docs/governance/LICENSE.md + +# Remove the OCA Bundles Navigation from the mkdocs.yml file +MKDOCS=mkdocs.yml +sed '/^- OCA Bundles:/,$d' ${MKDOCS} >${MKDOCS}.tmp +mv ${MKDOCS}.tmp ${MKDOCS} + +# Copy the MD files from the OCABundles folder into a docs/OCABundles folder +rm -rf docs/OCABundles +rsync -qavm --include='*.md' -f 'hide,! */' OCABundles docs/ + +# Execute the JSON file generator and copy the resulting files into the docs folder +./scripts/gen_ocabundlesjson.sh mkdocs +cp ocabundles.json docs/ +cp ocabundleslist.json docs/ + +# Replace (if needed) the OCA Bundles into the docs folder, deleting all but the MD files + +exit diff --git a/scripts/gen_ocabundlesjson.sh b/scripts/gen_ocabundlesjson.sh index 33a46718..fd00ab2d 100755 --- a/scripts/gen_ocabundlesjson.sh +++ b/scripts/gen_ocabundlesjson.sh @@ -1,24 +1,36 @@ #!/bin/bash +if [ "$1" == "mkdocs" ]; then + # Generating the mkdocs site + GENMKDOCS=true +fi + OCAIDSJSON=${PWD}/ocabundles.json OCALISTJSON=${PWD}/ocabundleslist.json +MKDOCSYML=${PWD}/mkdocs.yml TMPFILE=${PWD}/tmpfile.json ROOTDIR=${PWD} # Usage info show_help() { cat << EOF -Usage: gen_ocabundlesjson.sh +Usage: gen_ocabundlesjson.sh [mkdocs] Starting from the OCABundles folder in the current folder, and recurse through all the folders below. For each OCA Bundle found -- identified by the existance of a README.md file and an OCABundles.json file -- add the information about the -Bundle to the "ocabundles.json" and "ocabundleslist.json" files. Those two files -are generated in the current folder. In doing so, an appropriate JSON header is -put into the two files, the trailing comma is removed from the last entry of each -file, and an appropriate footer is put into the two files. +Bundle to the "ocabundles.json" and "ocabundleslist.json" files. If the parameter +"mkdocs" is passed in, also generate a navigation path for the bundles in the +repo "mkdocs.yml" file. + +The two JSON files are generated in the current folder. In doing so, an appropriate +JSON header is put into the two files, the trailing comma is removed from the last +entry of each file, and an appropriate footer is put into the two files. -Each entry in the files contains a "universal" SHA256 hash of the OCA Bundle +In the mkdocs.yml file, the current navigation is removed from the existing mkdocs.yml, +and the latest version generated in its place. + +Each entry in the JSON files contains a "universal" SHA256 hash of the OCA Bundle including, generated using the "shasum" utility with the options "-a256 -U". The script exits with an error if the OCABundles folder is not in the current @@ -36,9 +48,28 @@ if [ ! -d "OCABundles" ]; then exit 1 fi +# Raw URL encode the argument +rawurlencode() { + local string="${1}" + local strlen=${#string} + local encoded="" + local pos c o + + for (( pos=0 ; pos<strlen ; pos++ )); do + c=${string:$pos:1} + case "$c" in + [-_.~a-zA-Z0-9] ) o="${c}" ;; + * ) printf -v o '%%%02x' "'$c" + esac + encoded+="${o}" + done + echo "${encoded}" # You can either set a return variable (FASTER) + REPLY="${encoded}" #+or echo the result (EASIER)... or both... :p +} + + # In a folder with an OCABundle, process the file, and add the data for the bundle into the JSON files processBundle() { - RELPATH=$(echo ${PWD} | sed -e "s#${ROOTDIR}/##") BUNDLE_PATH=OCABundle.json SHASUM=$(shasum -a256 -U $BUNDLE_PATH | sed "s/ .*//") ID=$(grep '^| ' README.md | sed -e "/OCA Bundle/,100d" -e "/Identifier/d" -e "/----/d" -e 's/^| \([^|]*\) |.*/\1/' -e 's/\s*$//' -e 's/ /~/g') @@ -55,12 +86,39 @@ processBundle() { done } +insertBundleiframe () { + for id in ${ID}; do + # Do nothing, but $id will be set to the last one...use it + echo -n "" + done + # We're scanning the real OCABundles file, but want to update the copied files in the docs folder + FILE=${thisDir}/docs/$RELPATH/README.md + sed -e "/## Authorization/i## Credential Appearance\n\n\\<iframe src=\\"https://bcgov.github.io/aries-oca-explorer/identifier/$(rawurlencode ${id})\\" width=\\"100%\\" height=\\"800\\" frameborder=\\"0\\"\\>\\</iframe\\>\n" $FILE >$FILE.tmp + mv $FILE.tmp $FILE +} + +addNav() { + # Add entry to MKDocs Navigation + for ((num = 1; num <= ${INDENT}; num++)); do echo -n " " >>$MKDOCSYML; done + if [[ -f OCABundle.json ]]; then + echo "- ${RELPATH}/README.md" >>$MKDOCSYML + insertBundleiframe + else + echo "- "$(head -1 README.md | sed "s/[#]* //"): >>$MKDOCSYML + fi +} + # Recursively process the folders processFolder() { + INDENT=$((INDENT+1)) + RELPATH=$(echo ${PWD} | sed -e "s#${ROOTDIR}/##") # If the right files are in the folder, process it if [[ -f README.md && -f OCABundle.json ]]; then processBundle README.md OCABundle.json fi + if [[ -n "${GENMKDOCS}" && -f README.md ]]; then + addNav # Relies on $ID existing from previous processing + fi # Recurse into the directories of the folder for dir in *; do if [ -d $dir ]; then @@ -69,17 +127,22 @@ processFolder() { cd .. fi done + INDENT=$((INDENT-1)) } # Write the headers for the files echo -e "{" >${OCAIDSJSON} echo -e "[" >${OCALISTJSON} +if [ "$1" == "mkdocs" ]; then + echo -e "- OCA Bundles:" >>${MKDOCSYML} +fi # Start in the OCABundles folder cd OCABundles # Recursively process the folders +INDENT=0 processFolder cd ..