/
pages.cfc
114 lines (70 loc) · 1.97 KB
/
pages.cfc
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
component {
function home( ) {
items = getHome( application.settings.homeCount );
page = {
template : application.settings.templates.home,
content : items
};
return page;
}
function all( ) {
items = getHome( 99999 );
page = {
template : application.settings.templates.archive,
content : items
};
return page;
}
function view( page ) {
item = getFile( arguments.page );
page = {
template : application.settings.templates.view,
title : item.meta.title,
body : application.m.markdown( item.body ),
meta : item.meta
};
return page;
}
function feed( ) {
items = getHome( 99999 );
page = {
template : application.settings.templates.feed,
content : items
};
return page;
}
function getFile( page ) {
pages = DirectoryList( expandPath( application.settings.pageFolder ), false, 'query', '', 'desc' );
for ( x = 1; x <= pages.recordCount; x++ ) {
fileMatch = Find( arguments.page, pages.name[x] );
if ( fileMatch >= 1 ) {
file = pages.name[x];
break;
}
}
itemJSON = fileRead( expandPath( '/#application.settings.pageFolder#/#file#' ) );
item = deserializeJSON( itemJSON );
return item;
}
function getHome( count ) {
pages = DirectoryList( expandPath( application.settings.pageFolder ), false, 'query', '', 'desc' );
content = {};
if ( count > pages.recordCount ) {
count = pages.recordCount;
}
for ( x = 1; x <= count; x++ ) {
itemJSON = fileRead( expandPath( '/#application.settings.pageFolder#/#pages.name[x]#' ) );
item = deserializeJSON( itemJSON );
pageNameLen = len( pages.name[x] );
p = '';
pageUrl = right( lCase( replace( pages.name[x], '.md', p ) ), pageNameLen - 14);
content[x] = {
title : item.meta.title,
date : #DateTimeFormat( item.meta.date, application.settings.dateFormat )#,
body : application.m.markdown( item.body ),
url : pageUrl
};
}
return content;
}
}