Skip to content

Commit

Permalink
Update Nextra docs to reflect new app structure
Browse files Browse the repository at this point in the history
Build CloudFormation documentation dynamically

Build Terraform documentation dynamically
  • Loading branch information
mbklein committed Aug 9, 2023
1 parent e6c373a commit eea2fd0
Show file tree
Hide file tree
Showing 28 changed files with 834 additions and 100 deletions.
5 changes: 3 additions & 2 deletions docs/components/CallToAction.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import Link from 'next/link';
import classNames from './CallToAction.module.css';

const CallToAction = ({ href, text }) => {
const CallToAction = ({ href, text, newTab }) => {
const target = newTab ? '_blank' : '_self';
return (
<Link href={href} className={`nx-bg-primary-400/10 ${classNames.cta}`}>
<Link href={href} className={`nx-bg-primary-400/10 ${classNames.cta}`} target={target}>
{text} <span></span>
</Link>
);
Expand Down
9 changes: 6 additions & 3 deletions docs/components/HomepageHeader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ const HomepageHeader = () => {
<div className={classNames.header}>
<h1 className={classNames.headline}>Fast, zoomable images without servers</h1>
<p className={classNames.subtitle}>
A cost-effective, infinitely scalable IIIF 2.1 image api compliant service packaged as an AWS Serverless Application with minimum setup and no maintenance. Suitable for large institutional collections or small digital humanities projects.
<br />Community Driven. Open Source.
A cost-effective, infinitely scalable [IIIF Image API](https://iiif.io/api/image) v2.1 and v3.0 compliant service packaged
as an AWS Serverless Application with minimum setup and no maintenance. Suitable for large institutional collections or
small digital humanities projects.
<br/>Community Driven. Open Source.
</p>
<CallToAction href='/docs' text='Get started' />
<CallToAction newTab={true} href='https://console.aws.amazon.com/lambda/home#/create/app?applicationId=arn:aws:serverlessrepo:us-east-1:625046682746:applications/serverless-iiif' text='Deploy Now' />
&nbsp;<CallToAction href='/docs' text='Read the Docs' />

<Image
src={lightDiagram}
Expand Down
35 changes: 35 additions & 0 deletions docs/lib/cfn-reader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const fs = require('fs');
const YAML = require('yaml');
const templateFile = '../sam/template.yml';
const customTags = require('./cfn-tags');

function getParameters() {
const { Parameters } = getTemplate(templateFile);
const result = [];
for (const param in Parameters) {
result.push({ Name: param, ...Parameters[param] });
}
return result;
}

async function getPropertyList(opts = {}) {
const { compileMdx } = await import('nextra/compile');

const result = getParameters();
for (const param in result) {
const prop = result[param];
const mdx = await compileMdx(`${opts?.descPrefix}${prop.Description}`, { defaultShowCopyCode: true });
prop.Description = mdx.result;
}
return result;
}

function getTemplate(file) {
return YAML.parse(fs.readFileSync(file).toString(), { customTags });
}

module.exports = {
getParameters,
getPropertyList,
getTemplate
};
23 changes: 23 additions & 0 deletions docs/lib/cfn-tags.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const functionTags = {
'!GetAtt': { type: 'string', quoted: false },
'!Sub': { type: 'string', quoted: true },
'!Ref': { type: 'string', quoted: false }
};

module.exports = Object.entries(functionTags).map(([tag, { quoted }]) => {
const key = tag === '!Ref' ? 'Ref' : tag.replace(/^!/, 'Fn::');
return {
tag,
identify: (val) => {
const isTagged = Object.keys(val)[0] === key;
return isTagged;
},
resolve: (val) => {
return { [key]: val };
},
stringify: (val) => {
const result = val.value[key];
return quoted ? `"${result}"` : result;
}
};
});
32 changes: 32 additions & 0 deletions docs/lib/cloudformation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const { getTemplate } = require('./cfn-reader');
const { fence, stringify } = require('./render');

function example(format) {
const template = getTemplate('../examples/cloudformation/custom_hostname.yml');
return fence(stringify(template, format), format);
}

function parameterList(format = 'object') {
const { Parameters } = getTemplate('../sam/template.yml');
for (const key in Parameters) {
Parameters[key] = Parameters[key].Type;
}

const result = {
Type: 'AWS::Serverless::Application',
Properties: {
Location: {
ApplicationId:
'arn:aws:serverlessrepo:us-east-1:625046682746:applications/serverless-iiif-standalone-dev',
SemanticVersion: '5.0.0'
},
Parameters
}
};
return fence(stringify(result, format), format);
}

module.exports = {
example,
parameterList
};
41 changes: 41 additions & 0 deletions docs/lib/render.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const customTags = require('./cfn-tags');
const YAML = require('yaml');

function fence(code, format) {
return '```' + `${format}\n${code}\n` + '```';
}

function stringify(data, format) {
switch (format) {
case 'json':
return JSON.stringify(data, null, 2);
case 'yaml':
return YAML.stringify(data, { customTags });
default:
return data.toString();
}
}

function displayValue(v) {
if (v === '') return '""';
if (v.join) return v.join(' | ');
return v;
}

function present(v) {
if (v === 0) return true;
if (v === '') return true;
return !!v;
}

function snake(str) {
return str.replace(/\B([A-Z])/g, '_$1').toLowerCase();
}

module.exports = {
displayValue,
fence,
present,
snake,
stringify
};
Loading

0 comments on commit eea2fd0

Please sign in to comment.