forked from UIZE/UIZE-JavaScript-Framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_uize-site-build-index-pages.js
175 lines (153 loc) · 6.05 KB
/
_uize-site-build-index-pages.js
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
172
173
174
/*______________
| ______ | U I Z E J A V A S C R I P T F R A M E W O R K
| / / | ---------------------------------------------------
| / O / | MODULE : Index Pages Build Script
| / / / | AUTHOR : Chris van Rensburg (http://www.tomkidding.com)
| / / / /| | ONLINE : http://www.uize.com
| /____/ /__/_| | COPYRIGHT : (c)2009-2011 Chris van Rensburg
| /___ | LICENSE : Available under MIT License or GNU General Public License
|_______________| http://www.uize.com/license.html
*/
/*
DESCRIPTION
A script for WSH that builds index pages for examples, tool, and JavaScript modules.
*/
/*** boilerplate setup code for WSH build scripts ***/
var _setupFile = new ActiveXObject ('Scripting.FileSystemObject').OpenTextFile ('_build-script-setup.js',1);
eval (_setupFile.ReadAll ()) ();
_setupFile.Close ();
Uize.module ({
required:[
'Uize.Wsh',
'Uize.Wsh.BuildUtils',
'Uize.Template',
'Uize.String',
'Uize.String.Lines',
'Uize.Json',
'Uize.Data',
'Uize.Array.Sort',
'Uize.Data.PathsTree',
'UizeDotCom.BuildUtils'
],
builder:function () {
/*** Utility Functions ***/
function _buildIndexPage (_indexPageTemplatePath,_filesToIndex) {
Uize.Wsh.BuildUtils.processJstFile (_indexPageTemplatePath,{files:_filesToIndex});
}
var
_getFirstTitleSegment = UizeDotCom.BuildUtils.getFirstTitleSegment,
_moduleReferenceFiles = Uize.Wsh.BuildUtils.getHtmlFilesInfo ('reference',_getFirstTitleSegment)
;
/*** build index files for modules, explainers, and widgets ***/
_buildIndexPage (
'javascript-explainers.html.jst',
Uize.Wsh.BuildUtils.getHtmlFilesInfo ('explainers',_getFirstTitleSegment)
);
_buildIndexPage ('javascript-modules-index.html.jst',_moduleReferenceFiles);
_buildIndexPage (
'javascript-widgets.html.jst',
Uize.Wsh.BuildUtils.getHtmlFilesInfo ('widgets',_getFirstTitleSegment)
);
/*** build the UizeDotCom.ModulesTree module ***/
/*** build modules tree structure from list of module names ***/
var _modulesTree = Uize.Data.PathsTree.fromList (Uize.Data.map ('value.title',_moduleReferenceFiles),'.');
/*** write the modules tree module file ***/
Uize.Wsh.BuildUtils.writeDataModule (env.moduleFolderPath,'UizeDotCom.ModulesTree',_modulesTree);
/*** build the examples module and index pages ***/
var _examples = Uize.Wsh.BuildUtils.getHtmlFilesInfo ('examples',_getFirstTitleSegment);
/*** build the UizeDotCom.Examples module ***/
Uize.Wsh.BuildUtils.writeDataModule (env.moduleFolderPath,'UizeDotCom.Examples',_examples);
/*** build the examples by module page ***/
Uize.Wsh.BuildUtils.processJstFile ('javascript-examples-by-module.html.jst');
/*** build map of examples by keyword ***/
var _examplesByKeyword = {'':_examples};
for (
var _exampleNo = -1, _examplesLength = _examples.length, _example;
++_exampleNo < _examplesLength;
) {
var _keywordsStr = (_example = _examples [_exampleNo]).keywords;
if (_keywordsStr) {
var _keywords = _keywordsStr.split (' ');
for (var _keywordNo = -1, _keywordsLength = _keywords.length; ++_keywordNo < _keywordsLength;) {
var _keyword = _keywords [_keywordNo];
Uize.String.startsWith (_keyword,'Uize') ||
(_examplesByKeyword [_keyword] || (_examplesByKeyword [_keyword] = [])).push (_example)
;
}
}
}
/*** build examples index pages for each keyword ***/
var _indexPageTemplate = Uize.Wsh.BuildUtils.compileJstFile ('javascript-examples.html.jst');
for (var _keyword in _examplesByKeyword)
Uize.Wsh.writeFile ({
path:'javascript-' + _keyword + (_keyword && '-') + 'examples.html',
text:_indexPageTemplate ({files:_examplesByKeyword [_keyword],keyword:_keyword})
})
;
/*** build the UizeDotCom.ExamplesInfoForSiteMap module ***/
Uize.Wsh.BuildUtils.writeDataModule (
env.moduleFolderPath,'UizeDotCom.ExamplesInfoForSiteMap',
{
keywords:Uize.Data.getKeys (_examplesByKeyword).slice (1).sort (), // slice removes the '' keyword
tools:
Uize.Data.map (
function (_value) {return Uize.Data.filter (_value,['title','path'])},
_examplesByKeyword.tool
)
}
);
/*** build the news index pages ***/
var
_newsItems = Uize.Array.Sort.sortBy (
Uize.Wsh.BuildUtils.getHtmlFilesInfo ('news',_getFirstTitleSegment),
'value.title',
-1
),
_newsIndexPageTemplate = Uize.Wsh.BuildUtils.compileJstFile ('news.html.jst')
;
/*** build the latest news files ***/
var _latestNews = _newsItems.slice (0,50);
/*** build the latest news HTML page ***/
Uize.Wsh.writeFile ({
path:'latest-news.html',
text:_newsIndexPageTemplate ({files:_latestNews})
});
/*** build the latest news RSS file ***/
Uize.Wsh.BuildUtils.processJstFile (
'latest-news.rss.jst',
{
items:Uize.Data.map (
function (_value) {
return {
title:_value.title.replace (/^\d\d\d\d-\d\d-\d\d\s*-\s*/,''),
date:_value.title.slice (0,10),
link:'http://www.uize.com/' + _value.path,
description:_value.description
}
},
_latestNews
)
}
);
/*** build the home page, to update the news pod ***/
Uize.Wsh.BuildUtils.processJstFile ('index.html.jst',{latestNews:_latestNews});
/*** build map of news items by year ***/
var _newsItemsByYear = {};
for (
var _newsItemNo = -1, _newsItemsLength = _newsItems.length, _newsItem, _year;
++_newsItemNo < _newsItemsLength;
) {
var _year = (_newsItem = _newsItems [_newsItemNo]).title.slice (0,4);
(_newsItemsByYear [_year] || (_newsItemsByYear [_year] = [])).push (_newsItem);
}
/*** build news index pages for each year ***/
for (var _year in _newsItemsByYear)
Uize.Wsh.writeFile ({
path:'news-' + _year + '.html',
text:_newsIndexPageTemplate ({files:_newsItemsByYear [_year],year:_year})
})
;
/*** build the directory page ***/
Uize.Wsh.BuildUtils.processJstFile ('directory.html.jst');
}
});