Repository navigation
Expand file tree
/
Copy pathgen-documentation.js
More file actions
175 lines (150 loc) · 3.91 KB
/
Copy pathgen-documentation.js
File metadata and controls
175 lines (150 loc) · 3.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/* gen-documentation.js */
/* Requirements */
const fs = require('fs');
const path = require('path');
const nunjucks = require('nunjucks');
/* Constants */
const tagLineName = "Web Accessibility Consulting, Workshops and Free Tools for You";
const outputDirectory = './docs/';
const websiteURL = 'https://opwenweba11y.com';
const mainPages = [
{ content: 'content-index.njk',
title: 'Home',
link: 'Home',
filename: 'index.html'
},
{
dropdown: 'Outreach',
id: 'id-outreach',
pages: [
{ content: 'content-workshops.njk',
title: 'Workshops',
link: 'Workshops',
filename: 'workshops.html'
},
{ content: 'content-presentations.njk',
title: 'Presentations',
link: 'Presentations',
filename: 'presentations.html'
}
]
},
{ content: 'content-consulting.njk',
title: 'Consulting and Mentoring',
link: 'Consulting',
filename: 'consulting.html'
},
{ content: 'content-standards.njk',
title: 'Standards',
link: 'Standards',
filename: 'standards.html'
},
{
dropdown: 'Tools',
id: 'id-tools',
pages: [
{ content: 'content-tools.njk',
title: 'Open-Source Tools',
link: 'Open-Source Tools',
filename: 'tools.html'
},
{ content: 'content-system-colors.njk',
title: 'System Colors',
link: 'System Colors',
filename: 'system-colors.html'
}
]
},
{ content: 'content-about.njk',
title: 'About',
link: 'About',
filename: 'about.html'
}
];
// Create content files
function createNavigation(pages) {
console.log(`[create Navigation]`);
let html = '\n';
pages.forEach( item => {
console.log(`[create Navigation]: ${item.dropdown} ${item.filename}`);
if (item.dropdown) {
html += `
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle"
data-bs-toggle="dropdown"
href="#"
role="button"
aria-expanded="false"
aria-controls="${item.id}">${item.dropdown}</a>
<ul class="dropdown-menu" id="${item.id}">`;
item.pages.forEach( p => {
console.log(`[dropdown][page]: ${p.filename}`);
if (p.filename) {
html += `<li><a class="dropdown-item" href="${p.filename}">${p.link}</a></li>`;
}
else {
if (p.url) {
html += `<li><a class="dropdown-item" href="${p.url}">${p.link}</a></li>`;
}
else {
html += `<li><hr class="dropdown-divider"></li>`;
}
}
});
html += `
</ul>
</li>
`;
}
else {
html += `
<li class="nav-item">
<a class="nav-link" href="${item.filename}">${item.link}</a>
</li>
`;
}
});
html += '\n';
return html;
}
const mainNav = createNavigation(mainPages);
/* Helper functions */
function outputFile(fname, data) {
fs.writeFile(path.join(outputDirectory, fname), data, err => {
if (err) {
console.error(err)
return
}
})
}
function createPage(page, mainNav, dropdownName='', dropdownPages=false) {
if (page.filename) {
console.log(` [createPage]: ${page.filename}`);
outputFile(page.filename,
nunjucks.render('./src-docs/templates/page.njk',{
content: page.content,
navigation: mainNav,
dropdownName: dropdownName,
dropdownPages: dropdownPages,
websiteURL: websiteURL,
tagLineName: tagLineName,
title: page.title
})
);
}
}
// createPages(supportPages);
function createPages(pages) {
console.log(`[create pages]`);
pages.forEach( item => {
if (item.dropdown) {
item.pages.forEach( p => {
createPage(p, mainNav, item.dropdown, item.pages);
});
}
else {
createPage(item, mainNav);
}
});
}
createPages(mainPages);