Skip to content

Commit 9fed2e6

Browse files
authored
ARC 2042 - Create remaining pages and routes (#26)
1 parent 8cf60af commit 9fed2e6

10 files changed

+109
-30
lines changed

src/routes/atlassian-connect.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ export const connectAppDescriptor = {
164164
}
165165
},
166166
{
167-
url: "/auth",
167+
url: "/authentication",
168168
key: "acn-authentication",
169169
location: "none",
170170
name: {

src/routes/router.ts

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import path from "path";
2-
import * as fs from "fs";
32
import { Router, static as Static, Request, Response } from "express";
4-
import sanitizeHtml from "sanitize-html";
5-
import { marked } from "marked";
63
import { connectAppDescriptor, connectDescriptorGet } from "./atlassian-connect";
74
import { eventsRouter } from "./events";
85
import { webhooksRouter } from "./webhooks";
96
import { database } from "../db";
107
import { connectIframeJWTMiddleware } from "../middlewares/connect-iframe-jwt-middleware";
8+
import getMarkdownAndConvertToHtml from "../utils/markup";
119

1210
export const RootRouter = Router();
1311

@@ -26,31 +24,6 @@ RootRouter.use("/events", eventsRouter);
2624
// Jira webhooks we listen to as specified in the Connect JSON above
2725
RootRouter.use("/webhooks", webhooksRouter);
2826

29-
const renderer = new marked.Renderer();
30-
31-
renderer.link = (href: string, _, text: string): string => {
32-
if (href?.includes("https" || href?.includes("http"))) {
33-
return `<a target="_blank" href="${href}">${text}</a>`;
34-
} else {
35-
const page = href?.substring(1);
36-
return `<span class="link-span" id="${page}" data-connect-module-key="${page}">${text}</span>`;
37-
}
38-
};
39-
40-
const getMarkdownAndConvertToHtml = (fileName: string): string => {
41-
const filePath = path.join(__dirname, "..", "content", fileName);
42-
const contents = fs.readFileSync(filePath);
43-
// TODO - see if there's a way to modify the way we are using marked.js so we can pass data directly to HTML elements
44-
const markdownToHtml = marked.parse(contents.toString(), { renderer: renderer });
45-
46-
return sanitizeHtml(markdownToHtml, {
47-
allowedAttributes: {
48-
span: [ "class", "id", "data-connect-module-key" ],
49-
a: [ "href", "target" ]
50-
}
51-
});
52-
};
53-
5427
RootRouter.use(connectIframeJWTMiddleware);
5528

5629
RootRouter.get("/", (_req: Request, res: Response): void => {
@@ -66,6 +39,42 @@ RootRouter.get("/config", async (_req: Request, res: Response): Promise<void> =>
6639
});
6740
});
6841

42+
RootRouter.get("/authentication", async (_req: Request, res: Response): Promise<void> => {
43+
res.render("authentication", {
44+
pageContent: getMarkdownAndConvertToHtml("authentication.md")
45+
});
46+
});
47+
48+
RootRouter.get("/connect-library", async (_req: Request, res: Response): Promise<void> => {
49+
res.render("connect-js", {
50+
pageContent: getMarkdownAndConvertToHtml("connect-js.md")
51+
});
52+
});
53+
54+
RootRouter.get("/modules", async (_req: Request, res: Response): Promise<void> => {
55+
res.render("modules", {
56+
pageContent: getMarkdownAndConvertToHtml("modules.md")
57+
});
58+
});
59+
60+
RootRouter.get("/lifecycle-events", async (_req: Request, res: Response): Promise<void> => {
61+
res.render("lifecycle-events", {
62+
pageContent: getMarkdownAndConvertToHtml("lifecycle-events.md")
63+
});
64+
});
65+
66+
RootRouter.get("/making-api-requests", async (_req: Request, res: Response): Promise<void> => {
67+
res.render("api-requests", {
68+
pageContent: getMarkdownAndConvertToHtml("api-requests.md")
69+
});
70+
});
71+
72+
RootRouter.get("/marketplace", async (_req: Request, res: Response): Promise<void> => {
73+
res.render("marketplace", {
74+
pageContent: getMarkdownAndConvertToHtml("marketplace.md")
75+
});
76+
});
77+
6978
RootRouter.get("/logs/webhooks", async (_req: Request, res: Response): Promise<void> => {
7079
const clientKey = res.locals.jiraTenant?.clientKey;
7180
if (!clientKey) {

src/utils/markup.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import path from "path";
2+
import fs from "fs";
3+
import sanitizeHtml from "sanitize-html";
4+
import { marked } from "marked";
5+
6+
const renderer = new marked.Renderer();
7+
8+
renderer.link = (href: string, _, text: string): string => {
9+
if (href?.includes("https" || href?.includes("http"))) {
10+
return `<a target="_blank" href="${href}">${text}</a>`;
11+
} else {
12+
const page = href?.substring(1);
13+
return `<span class="link-span" id="${page}" data-connect-module-key="${page}">${text}</span>`;
14+
}
15+
};
16+
const getMarkdownAndConvertToHtml = (fileName: string): string => {
17+
const filePath = path.join(__dirname, "..", "content", fileName);
18+
const contents = fs.readFileSync(filePath);
19+
// TODO - see if there's a way to modify the way we are using marked.js so we can pass data directly to HTML elements
20+
const markdownToHtml = marked.parse(contents.toString(), { renderer: renderer });
21+
22+
return sanitizeHtml(markdownToHtml, {
23+
allowedAttributes: {
24+
span: [ "class", "id", "data-connect-module-key" ],
25+
a: [ "href", "target" ]
26+
}
27+
});
28+
};
29+
30+
31+
export default getMarkdownAndConvertToHtml;

src/views/api-requests.squirrelly

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{{@extendsFile('./layout.squirrelly')}}
2+
{{#title}}
3+
API Requests
4+
{{#content}}
5+
<div id="makingApiRequests" data-page-content="{{ it.pageContent }}"></div>
6+
{{/extendsFile}}

src/views/authentication.squirrelly

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{{@extendsFile('./layout.squirrelly')}}
2+
{{#title}}
3+
Authentication with JWT and Storage
4+
{{#content}}
5+
<div id="authWithJwtAndStorage" data-page-content="{{ it.pageContent }}"></div>
6+
{{/extendsFile}}

src/views/connect-js.squirrelly

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{{@extendsFile('./layout.squirrelly')}}
2+
{{#title}}
3+
Connect Library
4+
{{#content}}
5+
<div id="connectLibrary" data-page-content="{{ it.pageContent }}"></div>
6+
{{/extendsFile}}

src/views/lifecycle-events.squirrelly

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{{@extendsFile('./layout.squirrelly')}}
2+
{{#title}}
3+
Lifecycle Events
4+
{{#content}}
5+
<div id="lifecycleEvents" data-page-content="{{ it.pageContent }}"></div>
6+
{{/extendsFile}}

src/views/marketplace.squirrelly

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{{@extendsFile('./layout.squirrelly')}}
2+
{{#title}}
3+
API Requests
4+
{{#content}}
5+
<div id="marketplace" data-page-content="{{ it.pageContent }}"></div>
6+
{{/extendsFile}}

src/views/modules.squirrelly

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{{@extendsFile('./layout.squirrelly')}}
2+
{{#title}}
3+
Connect modules
4+
{{#content}}
5+
<div id="connectModulesForJira" data-page-content="{{ it.pageContent }}"></div>
6+
{{/extendsFile}}

static/js/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ document.addEventListener("DOMContentLoaded", () => {
3333
// Making API requests
3434
getPageElement("makingApiRequests");
3535

36-
// Marketplace
36+
// Connect JS library
37+
getPageElement("connectLibrary");
38+
39+
// Listing your app in Marketplace
3740
getPageElement("marketplace");
3841

3942
/**

0 commit comments

Comments
 (0)