Skip to content

Commit

Permalink
feat: major restructure, add Decap CMS configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
greatislander committed Mar 4, 2024
1 parent d4f07de commit 317fa69
Show file tree
Hide file tree
Showing 45 changed files with 10,418 additions and 7,218 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.DS_Store
.cache
_site
node_modules
dist
pdfs
pdfs
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lts/iron
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM node:20-alpine AS builder

WORKDIR /app

COPY package.json ./

RUN apk add --no-cache git

RUN npm install

COPY . ./

RUN npm run build

FROM nginx:1.25.4-alpine

COPY --from=builder /app/_site /usr/share/nginx/html
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,34 @@

This repository lets you create WCAG Audit Reports from Markdown files. It is based on [Eleventy WCAG Reporter](https://github.com/hidde/eleventy-wcag-reporter)
by Hidde de Vries.

## Usage

### To run locally in development mode

1. Install the required NPM packages: `npm install`
2. Run [Eleventy](http://11ty.dev) in development mode: `npm start`.

The website will be available at [http://localhost:8080](http://localhost:8080).

### To build and serve using Docker

You can build and serve the website from a [Docker](https://docs.docker.com/get-docker) container.

Once you have Docker installed, run the following commands to build a Docker image and start a container:

* Build the image: `docker build -t idrc-wcag-reporter .`
* Run the container: `docker run --name idrc-wcag-reporter -p 8000:80 idrc-wcag-reporter`

The website will be available at [http://localhost:8000](http://localhost:8000)

If you make changes to the website, repeat the steps to build the image and start a new container.

### To build for deployment to a personal web server

1. Install the required NPM packages: `npm install`
2. Run the build script: `npm run build`
3. Upload the contents of the `./_site/` directory to the web root of your server.

If you make changes to the website, repeat step 2 to build the website and upload any changed files from the `./_site/`
directory to the web root of your server.
61 changes: 0 additions & 61 deletions add-report.js

This file was deleted.

111 changes: 49 additions & 62 deletions eleventy.config.js
Original file line number Diff line number Diff line change
@@ -1,74 +1,61 @@
const fs = require("fs");
const path = require("path");
const markdownShortcode = require("eleventy-plugin-markdown-shortcode");
const syntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight");
const scTable = require("./src/_utils/scTable.js");
const sampleImage = require("./src/_utils/sampleImage.js");
const scUri = require("./src/_utils/scUri.js");
const scName = require("./src/_utils/scName.js");
const slugify = require("./src/_utils/slugify.js");
import { EleventyRenderPlugin } from "@11ty/eleventy";
import syntaxHighlightPlugin from "@11ty/eleventy-plugin-syntaxhighlight";
import scTable from "./src/_utils/scTable.js";
import scUri from "./src/_utils/scUri.js";
import sanitizeNumber from "./src/_utils/sanitizeNumber.js";
// const newGitHubIssueUrl = require("new-github-issue-url");

const reportsFolderRelative = "src/reports";
const reportsFolder = path.join(__dirname, reportsFolderRelative);

const reports = fs.readdirSync(reportsFolder).filter((reportName) => {
const reportPath = path.join(reportsFolder, reportName);
return fs.existsSync(reportPath) && fs.lstatSync(reportPath).isDirectory();
});

const sanitizeNumber = (numberWithDots) => {
const numberString = numberWithDots
.split(".")
.map((numb) => (numb = Number(numb) < 10 ? "0" + numb : numb))
.join("");
return Number(numberString);
};

module.exports = function (eleventyConfig) {
export default function (eleventyConfig) {
eleventyConfig.addFilter("sc_uri", scUri);
eleventyConfig.addFilter("sc_name", scName);

eleventyConfig.addFilter("slugify", slugify);
eleventyConfig.addFilter("newIssueUrl", (url) => {
if (url.indexOf("gitlab")) {
return;
}
});

eleventyConfig.addNunjucksShortcode("sc_table", scTable);
eleventyConfig.addNunjucksShortcode("sample_image", sampleImage);
eleventyConfig.addNunjucksAsyncShortcode("sc_table", scTable);

eleventyConfig.addLayoutAlias("report", "report.njk");

eleventyConfig.addPlugin(markdownShortcode);
eleventyConfig.addPlugin(syntaxHighlight);
eleventyConfig.addPlugin(EleventyRenderPlugin);
eleventyConfig.addPlugin(syntaxHighlightPlugin);

eleventyConfig.addCollection("issues", function (collectionApi) {
return collectionApi
.getFilteredByGlob("src/issues/*.md")
.filter(
(item) => !(item.data.sc === "none") && !(item.data.sc === undefined)
)
.sort((a, b) => {
const numbA = sanitizeNumber(a.data.sc);
const numbB = sanitizeNumber(b.data.sc);
if (numbA < numbB) return -1;
if (numbA > numbB) return 1;
return 0;
});
});

eleventyConfig.addCollection("tips", function (collectionApi) {
return collectionApi
.getFilteredByGlob("src/issues/*.md")
.filter((item) => item.data.sc === "none");
});

// create a collection of issues specific to each report, sorted by success criterion
for (let i = 0; i < reports.length; i++) {
eleventyConfig.addCollection(reports[i], function (collectionApi) {
return collectionApi
.getFilteredByGlob(`${reportsFolderRelative}/${reports[i]}/**/*.md`)
.filter(
(item) => !(item.data.sc === "none") && !(item.data.sc === undefined)
)
.sort((a, b) => {
const numbA = sanitizeNumber(a.data.sc);
const numbB = sanitizeNumber(b.data.sc);
if (numbA < numbB) return -1;
if (numbA > numbB) return 1;
return 0;
});
});
}
eleventyConfig.addPassthroughCopy({
"src/admin/config.yml": "admin/config.yml",
});

// create a collection of “tips” specific to each report (all issues with sc set to "none")
for (let i = 0; i < reports.length; i++) {
eleventyConfig.addCollection(
`${reports[i]}-tips`,
function (collectionApi) {
return collectionApi
.getFilteredByGlob(`${reportsFolderRelative}/${reports[i]}/**/*.md`)
.filter((item) => item.data.sc === "none");
}
);
}
eleventyConfig.addPassthroughCopy({
"node_modules/decap-cms/dist/decap-cms.js": "lib/cms/decap-cms.js",
"node_modules/decap-cms/dist/decap-cms.js.map": "lib/cms/decap-cms.js.map",
"node_modules/prop-types/prop-types.min.js": "lib/cms/prop-types.min.js",
"node_modules/react/umd/react.development.js":
"lib/cms/react.development.js",
"node_modules/react/umd/react.production.min.js":
"lib/cms/react.production.min.js",
});

// Base Config
return {
dir: {
input: "src",
Expand All @@ -80,4 +67,4 @@ module.exports = function (eleventyConfig) {
htmlTemplateEngine: "njk",
markdownTemplateEngine: "njk",
};
};
}
Loading

0 comments on commit 317fa69

Please sign in to comment.