Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix last updated date on product pages #96

Merged
merged 2 commits into from
Jun 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions gulpfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ gulp.task("build general pages", () => {
gulp.task(
"build pages",
gulp.parallel(
...getProductPageBuildTasks(products),
...getDirectoryPagesTasks(products),
"build general pages",
"build api"
...getProductPageBuildTasks(products),
...getDirectoryPagesTasks(products),
"build general pages",
"build api"
)
);

Expand Down
29,568 changes: 7,094 additions & 22,474 deletions package-lock.json

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
"@fortawesome/fontawesome-free": "^5.15.1",
"@iarna/toml": "^2.2.5",
"@types/gulp": "^4.0.7",
"@types/jest": "^25.2.3",
"@types/jest": "^26",
"@types/node": "^14.14.14",
"@typescript-eslint/eslint-plugin": "^3.10.1",
"@typescript-eslint/parser": "^3.10.1",
"a17t": "^0.2.9",
"autoprefixer": "^10.2.6",
"axios": "^0.21.1",
"babel-jest": "^26.6.3",
"babel-jest": "^27",
"babel-plugin-polyfill-corejs2": "^0.2.0",
"babel-plugin-polyfill-corejs3": "^0.2.0",
"babel-plugin-polyfill-regenerator": "^0.2.0",
Expand All @@ -42,8 +42,8 @@
"handlebars-helpers": "^0.10.0",
"image-size": "^0.8.3",
"is-core-module": "^2.4.0",
"jest": "^26.6.3",
"jest-cli": "^26.6.3",
"jest": "^27",
"jest-cli": "^27",
"jest-junit": "^11.1.0",
"jssoup": "0.0.11",
"lunr": "^2.3.9",
Expand All @@ -53,6 +53,7 @@
"queue-microtask": "^1.2.3",
"run-sequence": "^2.2.1",
"sharp": "^0.25.4",
"simple-git": "^2.40.0",
"tailwindcss": "^2.1.2",
"toml": "^3.0.0",
"ts-node": "^8.10.2",
Expand Down
4 changes: 3 additions & 1 deletion src/build/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@ export function getProductPageBuildTasks(products: Product[]) {
const productPageBuildTasks = [];
for (const product of products) {
const taskName = `build ${product.slug}`;
gulp.task(taskName, () => {

gulp.task(taskName, async () => {
return gulp
.src("./src/templates/pages/product.hbs")
.pipe(
hbsFactory({
product: product,
lastUpdated: await product.lastUpdated,
description: `${product.name} has a score of ${product.score}/10 on PrivacySpy, an open project to rate and annotate privacy policies.`,
})
)
Expand Down
6 changes: 6 additions & 0 deletions src/parsing/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import fs from "fs";
import toml from "@iarna/toml";
import { RubricQuestion, RubricSelection, Product, Contributor } from "./types";
import { getQuestionBySlug, getOptionBySlug } from "./utils";
import simpleGit, {SimpleGit} from 'simple-git';

const git: SimpleGit = simpleGit();

export function loadContributors(): Contributor[] {
const data: object = toml.parse(
Expand Down Expand Up @@ -51,11 +54,14 @@ export function loadProducts(
for (const file of files) {
const rubric: RubricSelection[] = [];

const lastUpdated = git.log({file: "products/" + file}).then(x => x.latest ? new Date(x.latest.date).toDateString() : "Unknown");

const product: Product = {
contributors: [],
updates: [],
hostnames: [],
sources: [],
lastUpdated,
...(toml.parse(
fs.readFileSync("products/" + file, {
encoding: "utf-8",
Expand Down
2 changes: 1 addition & 1 deletion src/parsing/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ export interface Product {
children: Product[];
rubric: RubricSelection[];
updates: Update[];
lastUpdated: Date;
lastUpdated: Promise<Date>;
contributors: Contributor[];
}
2 changes: 1 addition & 1 deletion src/templates/pages/product.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
<section class="w-full mt-10 text-center md:text-left md:w-1/5 md:mt-0">
<div class="mb-6">
<p class="text-sm text-gray-400">Last Updated</p>
<p class="mt-1 text-sm text-black">May 5, 2020</p>
<p class="mt-1 text-sm text-black">{{lastUpdated}}</p>
</div>
<div class="my-6">
<p class="text-sm text-gray-400">Sources</p>
Expand Down
5 changes: 5 additions & 0 deletions src/tests/product.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ for (const product of products) {
expect(product.slug.toLowerCase()).toEqual(product.slug);
});

// The following isn't a particularly useful test, but it ensures that Jest waits for all handles to close.
test(`last updated must load`, async () => {
expect(await product.lastUpdated).toBeDefined();
});

describe(`must have hostname(s) {hostnames}`, () => {
test("that exist", () => {
expect(product.hostnames.length).toBeGreaterThan(0);
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"target": "es6",
"esModuleInterop": true,
"esModuleInterop": true
}
}