-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsettings.rs
318 lines (268 loc) · 12.4 KB
/
settings.rs
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
#[cfg(production)]
pub const PRODUCTION: bool = true;
#[cfg(not(production))]
pub const PRODUCTION: bool = false;
include!("private.rs");
/*
private.rs will contain:
#[cfg(not(production))]
pub const DATABASE_URL: &'static str = "postgres://dbuser:dbpass@localhost/blog";
#[cfg(production)]
pub const DATABASE_URL: &'static str = "postgres://dbuser:dbpass@localhost/blog";
*/
// DEVELOPMENT SETTINGS
#[cfg(not(production))]
pub const BLOG_URL: &'static str = "http://localhost:8000/";
#[cfg(not(production))]
pub const USER_LOGIN_URL: &'static str = "http://localhost:8000/user";
#[cfg(not(production))]
pub const ADMIN_LOGIN_URL: &'static str = "http://localhost:8000/admin";
#[cfg(not(production))]
pub const TEST_LOGIN_URL: &'static str = "http://localhost:8000/login";
#[cfg(not(production))]
pub const CREATE_FORM_URL: &'static str = "http://localhost:8000/create";
#[cfg(not(production))]
pub const EDIT_FORM_URL: &'static str = "http://localhost:8000/edit";
#[cfg(not(production))]
pub const MANAGE_URL: &'static str = "http://localhost:8000/manage";
#[cfg(not(production))]
pub const MAX_CREATE_TITLE: usize = 120;
#[cfg(not(production))]
pub const MAX_CREATE_DESCRIPTION: usize = 400;
#[cfg(not(production))]
pub const MAX_CREATE_TAGS: usize = 250;
#[cfg(not(production))]
const MAX_ATTEMPTS: i16 = 8; // 8
#[cfg(not(production))]
const LOCKOUT_DURATION: u32 = 8; // 6 seconds // 900 seconds = 15 minutes
#[cfg(not(production))]
const DB_BACKUP_SCRIPT: &'static str = r"scripts\db_backup-dev.bat";
// After the specified number of attempts, the next account lock will permanently lock the account
#[cfg(not(production))]
const ADMIN_LOCK: i16 = 20;
// After the specified number of attempts, the next account lock will permanently lock the account
#[cfg(not(production))]
const USER_LOCK: i16 = 40;
// Path to the article header images internally
#[cfg(not(production))]
const INTERNAL_IMGS: &'static str = r"c:\code\lang\rust\proj\blogr\static\imgs";
#[cfg(not(production))]
pub const HITS_SAVE_INTERVAL: usize = 2;
// Default http caching value (max age value)
#[cfg(not(production))]
const DEFAULT_TTL: isize = 3600; // 1*60*60 = 1 hour, 43200=1/2 day, 86400=1 day
// If no description is found take a specified amount of characters from the article body
#[cfg(not(production))]
pub const DESC_LIMIT: usize = 300;
// The directory to load static pages from
#[cfg(not(production))]
const STATIC_PAGES_DIR: &'static str = "pages";
// Multi Segment Paths are those that have multiple / in the uri
// ex: /article/<aid>/Search_Engine_Friendly_Title
// const MULTI_SEGMENT_PATHS: Vec<&'static str> = vec!["article", "search", "tag"];
#[cfg(not(production))]
const MULTI_SEGMENT_PATHS: &[&'static str] = &["article", "search", "tag", "content", "download"];
// const MULTI_SEGMENT_PATHS: &[&'static str] = [""];
#[cfg(not(production))]
const PAGE_TEMPLATES: &[&'static str] = &["page-template", "page-code-template", "page-blank-template"];
#[cfg(not(production))]
const DEFAULT_PAGE_TEMPLATE: &'static str = "page-template";
#[cfg(not(production))]
const HIT_COUNTER_LOG: &'static str = "logs/page_stats.json";
#[cfg(not(production))]
const TOTAL_HITS_LOG: &'static str = "logs/total_views.json";
#[cfg(not(production))]
const UNIQUE_HITS_LOG: &'static str = "logs/unique_stats.json";
#[cfg(not(production))]
// const DOWNLOADABLE_LOGS: &[&'static str] = vec!["page_stats.json", "unique_stats.json", "total_views.json"];
const DOWNLOADABLE_LOGS: &[&'static str] = &["page_stats.json", "unique_stats.json", "total_views.json"];
// Enables fallback database queries if cache is disabled
#[cfg(not(production))]
const CACHE_FALLBACK: bool = true;
#[cfg(not(production))]
const CACHE_ENABLED: bool = true;
#[cfg(not(production))]
const ENABLE_DEBUG_OUTPUT: bool = false;
#[cfg(not(production))]
const DEBUG_TIMING: bool = true;
// The ONE_RESULT_SHOW_FULL will show the full article, not just the
// article's description, when only one article is to be displayed.
// This will display the full article even if there are multiple pages
// but only one article being displayed per page, or if its the last page
// and there is only one article to display
#[cfg(not(production))]
const ONE_RESULT_SHOW_FULL: bool = true;
// If ONE_RESULT_SHOW_FULL is enabled, and ONE_RESULT_ONE_PAGE is enabled,
// then show the full article if only one article is displayed, but only
// if there is only a single page to display, do not show the full article
// if there are multiple pages, like if only one item per page is being shown
// or it is the last page and only one item to show - then truncate the body.tion))]
#[cfg(not(production))]
const ONE_RESULT_ONE_PAGE: bool = false;
// #[cfg(not(production))]
// static DEFAULT_PAGE_MENU: Option<Vec<TemplateMenu>> = Some(vec![TemplateMenu::new("Rust Tutorials".to_owned(), "/content/tutorials".to_owned(), "")]);
// static DEFAULT_PAGE_MENU: Option<Vec<TemplateMenu>> = Some(vec![TemplateMenu {name: "Rust Tutorials".to_owned(), url: format!("{}content/tutorials", BLOG_URL), separator: false, classes: String::new()}]);
// Comrak Markdown rendering default settings
#[cfg(not(production))]
pub const COMRAK_OPTIONS: ComrakOptions = ComrakOptions {
hardbreaks: true, // \n => <br>\n
width: 120usize,
github_pre_lang: false,
ext_strikethrough: true, // hello ~world~ person.
ext_tagfilter: true, // filters out certain html tags
ext_table: true, // | a | b |\n|---|---|\n| c | d |
ext_autolink: true,
ext_tasklist: true, // * [x] Done\n* [ ] Not Done
ext_superscript: true, // e = mc^2^
ext_header_ids: None, // None / Some("some-id-prefix-".to_string())
ext_footnotes: true, // Hi[^x]\n\n[^x]: A footnote here\n
};
// PRODUCTION SETTINGS
#[cfg(production)]
pub const BLOG_URL: &'static str = "https://vishus.net/";
#[cfg(production)]
pub const USER_LOGIN_URL: &'static str = "https://vishus.net/user";
#[cfg(production)]
pub const ADMIN_LOGIN_URL: &'static str = "https://vishus.net/admin";
#[cfg(production)]
pub const TEST_LOGIN_URL: &'static str = "https://vishus.net/login";
#[cfg(production)]
pub const CREATE_FORM_URL: &'static str = "https://vishus.net/create";
#[cfg(production)]
pub const EDIT_FORM_URL: &'static str = "https://vishus.net/edit";
#[cfg(production)]
pub const MANAGE_URL: &'static str = "https://vishus.net/manage";
#[cfg(production)]
pub const MAX_CREATE_TITLE: usize = 50;
#[cfg(production)]
pub const MAX_CREATE_DESCRIPTION: usize = 500;
#[cfg(production)]
pub const MAX_CREATE_TAGS: usize = 250;
#[cfg(production)]
const MAX_ATTEMPTS: i16 = 5; // 8
#[cfg(production)]
const LOCKOUT_DURATION: u32 = 900; // 6 seconds // 900 seconds = 15 minutes
#[cfg(production)]
const DB_BACKUP_SCRIPT: &'static str = r"bash";
#[cfg(production)]
const DB_BACKUP_ARG: &'static str = r"scripts/db_backup-prod.sh";
// After the specified number of attempts, the next account lock will permanently lock the account
#[cfg(production)]
const ADMIN_LOCK: i16 = 15;
// After the specified number of attempts, the next account lock will permanently lock the account
#[cfg(production)]
const USER_LOCK: i16 = 40;
// Path to the article header images internally
#[cfg(production)]
const INTERNAL_IMGS: &'static str = r"/var/www/html/imgs";
#[cfg(production)]
pub const HITS_SAVE_INTERVAL: usize = 35;
// Default http caching value (max age value)
#[cfg(production)]
const DEFAULT_TTL: isize = 3600; // 1*60*60 = 1 hour, 43200=1/2 day, 86400=1 day
// If no description is found take a specified amount of characters from the article body
#[cfg(production)]
pub const DESC_LIMIT: usize = 300;
// The directory to load static pages from
#[cfg(production)]
const STATIC_PAGES_DIR: &'static str = "pages";
// Multi Segment Paths are those that have multiple / in the uri
// ex: /article/<aid>/Search_Engine_Friendly_Title
// const MULTI_SEGMENT_PATHS: Vec<&'static str> = vec!["article", "search", "tag"];
#[cfg(production)]
const MULTI_SEGMENT_PATHS: &[&'static str] = &["article", "search", "tag", "content", "download"];
#[cfg(production)]
const PAGE_TEMPLATES: &[&'static str] = &["page-template", "page-code-template", "page-blank-template"];
#[cfg(production)]
const DEFAULT_PAGE_TEMPLATE: &'static str = "page-template";
#[cfg(production)]
const HIT_COUNTER_LOG: &'static str = "logs/page_stats.json";
#[cfg(production)]
const TOTAL_HITS_LOG: &'static str = "logs/total_views.json";
#[cfg(production)]
const UNIQUE_HITS_LOG: &'static str = "logs/unique_stats.json";
#[cfg(production)]
// const DOWNLOADABLE_LOGS = vec!["page_stats.json", "unique_stats.json", "total_views.json"];
const DOWNLOADABLE_LOGS: &[&'static str] = &["page_stats.json", "unique_stats.json", "total_views.json"];
// Enables fallback database queries if cache is disabled
#[cfg(production)]
const CACHE_FALLBACK: bool = true;
#[cfg(production)]
const CACHE_ENABLED: bool = true;
#[cfg(production)]
const ENABLE_DEBUG_OUTPUT: bool = false;
#[cfg(production)]
const DEBUG_TIMING: bool = false;
// The ONE_RESULT_SHOW_FULL will show the full article, not just the
// article's description, when only one article is to be displayed.
// This will display the full article even if there are multiple pages
// but only one article being displayed per page, or if its the last page
// and there is only one article to display
#[cfg(production)]
const ONE_RESULT_SHOW_FULL: bool = true;
// If ONE_RESULT_SHOW_FULL is enabled, and ONE_RESULT_ONE_PAGE is enabled,
// then show the full article if only one article is displayed, but only
// if there is only a single page to display, do not show the full article
// if there are multiple pages, like if only one item per page is being shown
// or it is the last page and only one item to show - then truncate the body.
#[cfg(production)]
const ONE_RESULT_ONE_PAGE: bool = false;
// #[cfg(production)]
// static DEFAULT_PAGE_MENU: Option<Vec<TemplateMenu>> = Some(vec![TemplateMenu::new("Rust Tutorials".to_owned(), "/content/tutorials".to_owned(), "")]);
// static DEFAULT_PAGE_MENU: Option<Vec<TemplateMenu>> = Some(vec![TemplateMenu {name: "Rust Tutorials".to_owned(), url: format!("{}content/tutorials", BLOG_URL), separator: false, classes: String::new()}]);
// Comrak Markdown rendering default settings
#[cfg(production)]
pub const COMRAK_OPTIONS: ComrakOptions = ComrakOptions {
hardbreaks: true, // \n => <br>\n
width: 120usize,
github_pre_lang: false,
ext_strikethrough: true, // hello ~world~ person.
ext_tagfilter: true, // filters out certain html tags
ext_table: true, // | a | b |\n|---|---|\n| c | d |
ext_autolink: true,
ext_tasklist: true, // * [x] Done\n* [ ] Not Done
ext_superscript: true, // e = mc^2^
ext_header_ids: None, // None / Some("some-id-prefix-".to_string())
ext_footnotes: true, // Hi[^x]\n\n[^x]: A footnote here\n
};
lazy_static! {
static ref BASE: &'static str = if BLOG_URL.ends_with("/") {
&BLOG_URL[..BLOG_URL.len()-1]
} else {
&BLOG_URL
};
}
// The production and development versions of the menu items allows
// links to be added with different addresses depending on dev/prod environment
// ex: the links in the dev version could use http://localhost:8000/
// where as the prod version could use https://your_domain.com/
#[cfg(production)]
lazy_static! {
static ref DEFAULT_PAGE_MENU: Option<Vec<TemplateMenu>> = Some(
vec![
TemplateMenu::new("Home".to_owned(), "/".to_owned(), ""),
TemplateMenu::new("Rust Tutorials".to_owned(), "/content/tutorials".to_owned(), ""),
TemplateMenu::new("Tags".to_owned(), "/all_tags".to_owned(), ""),
TemplateMenu::new("About".to_owned(), "/content/about-me".to_owned(), ""),
]
);
}
#[cfg(not(production))]
lazy_static! {
static ref DEFAULT_PAGE_MENU: Option<Vec<TemplateMenu>> = Some(
vec![
TemplateMenu::new("Home".to_owned(), "/".to_owned(), ""),
TemplateMenu::new("Rust Tutorials".to_owned(), "/content/tutorials".to_owned(), ""),
TemplateMenu::new("Tags".to_owned(), "/all_tags".to_owned(), ""),
TemplateMenu::new("About".to_owned(), "/content/about-me".to_owned(), ""),
]
);
}
#[cfg(production)]
lazy_static! {
static ref DEFAULT_PAGE_DROPDOWN: Option<Vec<TemplateMenu>> = None;
}
#[cfg(not(production))]
lazy_static! {
static ref DEFAULT_PAGE_DROPDOWN: Option<Vec<TemplateMenu>> = None;
}