├── .env ├── .gitignore ├── Cargo.toml ├── README.md ├── schema └── schema.sql ├── scripts └── create_test_user.sh ├── src ├── middleware.rs ├── page_forum.rs ├── page_forum │ ├── .keep │ ├── article_page.rs │ ├── comment_page.rs │ ├── index_page.rs │ ├── section_page.rs │ └── user_page.rs ├── page_forum_bin.rs └── tantivy_index.rs ├── static ├── css │ ├── base.css │ └── gruvbox-light.css ├── favicon.ico ├── img │ ├── qrcode_rust.png │ └── rust-logo.svg └── js │ ├── highlight.pack.js │ └── jquery.min.js ├── tomls └── i18n.toml └── views └── forum ├── account.html ├── acknowledgement.html ├── admin └── .keep ├── admin_landing_page.html ├── arrange_sections.html ├── article.html ├── article_list_paging.html ├── base.html ├── delete_article.html ├── delete_comment.html ├── edit_article.html ├── edit_comment.html ├── edit_section.html ├── footer.html ├── header.html ├── index.html ├── login_with3rd.html ├── login_with_admin.html ├── manage_section_view.html ├── manage_section_view_articles.html ├── new_article.html ├── new_comment.html ├── new_section.html ├── search_result.html ├── section.html ├── user_change_pwd_page.html └── user_modifynickname_page.html /.env: -------------------------------------------------------------------------------- 1 | DBURL=postgres://postgres:123@localhost/forustm 2 | REDISURL=redis://127.0.0.1/0 3 | BINDADDR=127.0.0.1 4 | BINDPORT=8081 5 | RUSODA_LANG=cn 6 | #HOST_DOMAIN=https://rust.cc 7 | HOST_DOMAIN=http://127.0.0.1:8081 8 | NUMBER_ARTICLE_PER_PAGE=5 9 | BIG_NUMBER_ARTICLE_PER_PAGE=50 10 | NUMBER_COMMENT_PER_PAGE=5 11 | CACHE=0 12 | GITHUB_APP_CLIENT_ID=xxxx 13 | GITHUB_APP_CLIENT_SECRET=xxxxx 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | **/*.rs.bk 3 | search_index/ 4 | Cargo.lock 5 | 6 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "forustm2" 3 | version = "0.1.1" 4 | authors = ["Daogang Tang "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | log = "0.4" 9 | env_logger = "0.6.0" 10 | dotenv = "0.13.0" 11 | uuid = {features = ["serde", "v4"], version = "0.5.1"} 12 | sapper = {version = "0.2"} 13 | sapper_std = {version = "0.2", features=["monitor"]} 14 | rusoda = {git="https://github.com/daogangtang/rusoda"} 15 | tantivy = "0.12" 16 | jieba-rs = "0.4" 17 | cang-jie = "0.7" 18 | serde = "1.0" 19 | serde_json = "1.0" 20 | serde_derive = "1.0" 21 | chrono = "0.4" 22 | crossbeam = "0.7" 23 | 24 | [[bin]] 25 | name = "page_forum_bin" 26 | path = "src/page_forum_bin.rs" 27 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Forustm 2 | 3 | Forustm is a forum written in Rust. 4 | 5 | #### External Dependencies 6 | 7 | Now, we use postgresql as main db, to store all things, and use redis to store user login session key. 8 | 9 | - Redis, version > 2 10 | - Postgresql, version > 9 11 | 12 | 13 | #### Structure 14 | 15 | This forum is developed by [Sapper](https://github.com/daogangtang/sapper), which is a rapid web developing framework (which is based on syncronized hyper v0.10.26 now, but later will update to latest async/await branch). 16 | 17 | Although it is not well documented now, it ran as a community forum for three years (wow :) ) 18 | 19 | But I will surely supply more documentations on it, in fact I am waiting the release of `async-std` and correspoding hyper branch version, or other http server crate version. 20 | 21 | 22 | #### Features 23 | 24 | - Section CRUD 25 | - Article CRUD 26 | - User blog 27 | - User blog planet 28 | - I18n 29 | - Fulltext searching based on tantivy (but now commented, need to update to latest tantivy version) 30 | - User system oauthed by github.com (this is the only user system currently, we don't supply opening registration) 31 | - Tera rendering engine 32 | - Markdown text support for article content and comment content 33 | - Rss subscribing 34 | 35 | We write this project for: 36 | 37 | 1. Making a forum for rust community (must use rust to implement it) 38 | 2. Giving a practical example for sapper project 39 | 3. Keeping code clean and easy to learn 40 | 41 | 42 | #### Db Operation 43 | 44 | You will find ./schema/schema.sql, you need use pg client, such as `psql`, to make a new empty db in postgresql before bootuping forustm bin. 45 | 46 | 1. use psql to connect to pg: `psql` 47 | 2. create an new db: `create database foobar;` 48 | 3. connect this new db: `\c foobar;` 49 | 4. import sql file: `\i {project_path}/schema/schema.sql;` 50 | 51 | That's all operations on db. 52 | 53 | 54 | #### Configuration 55 | 56 | You need an `.env` file in your project directory, whose content as like bellow: 57 | 58 | ``` 59 | DBURL=postgres://postgres:pwd@localhost/forustm 60 | REDISURL=redis://127.0.0.1/0 61 | BINDADDR=127.0.0.1 62 | BINDPORT=8081 63 | RUSODA_LANG=en 64 | #HOST_DOMAIN=https://rust.cc 65 | #HOST_DOMAIN=http://127.0.0.1:8080 66 | NUMBER_ARTICLE_PER_PAGE=20 67 | NUMBER_COMMENT_PER_PAGE=20 68 | CACHE=0 69 | GITHUB_APP_CLIENT_ID=xxxx 70 | GITHUB_APP_CLIENT_SECRET=xxxxxx 71 | ``` 72 | 73 | #### Bootup 74 | 75 | ``` 76 | cargo build 77 | cargo run --bin page_forum_bin 78 | ``` 79 | 80 | and you will see a boot up server which is bounded to the port you configured just now. 81 | 82 | #### Operating 83 | 84 | And then, you can operate everything in the browser. 85 | 86 | - You can go to `http://127.0.0.1:{port}/login_with_admin`, and account: `admin@admin.com`, password: `admin` to initialize the bootup content of this site. 87 | - go `http://127.0.0.1:{port}/admin_secion` to create sections, manage section orders, manage the top articles in one section, etc 88 | 89 | 90 | #### Scripts 91 | 92 | You can use ./scripts/create_test_user.sh to create some test user to login in browser. 93 | 94 | The parameters in this script file could be modified by your need. 95 | 96 | #### Good Lucky 97 | 98 | This is not a detailed documentation, so, forgive me, will do more on it. 99 | 100 | #### Future Plan 101 | 102 | Rust community should own its own full-featured forum application, the long aim of this project, is to replace the officail [Rust users forum](https://users.rust-lang.org/) keeped by Rust officail team. 103 | 104 | #### Referrences 105 | 106 | - [wasm-dev.org](https://wasm-dev.org) 107 | - [rust.cc](https://rust.cc) / [rust-china.org](https://rust-china.org) 108 | - [Rustforce](https://rustforce.net) 109 | - [substrater.org](https://substrater.org) 110 | - [Rust Users](https://users.rust-lang.org/) 111 | -------------------------------------------------------------------------------- /schema/schema.sql: -------------------------------------------------------------------------------- 1 | -- Your SQL goes here 2 | 3 | create extension pgcrypto; 4 | 5 | CREATE TABLE ruser ( 6 | id uuid primary key default gen_random_uuid(), 7 | account VARCHAR unique NOT NULL, 8 | password VARCHAR NOT NULL, 9 | salt VARCHAR NOT NULL, 10 | nickname VARCHAR NOT NULL, 11 | avatar VARCHAR, 12 | wx_openid VARCHAR, 13 | say VARCHAR, 14 | signup_time timestamp not null default current_timestamp, 15 | role smallint not null default 0, 16 | status smallint not null default 0, 17 | github varchar 18 | ); 19 | 20 | create index user_account on ruser (account); 21 | 22 | insert into ruser (account, password, salt, role, nickname) values 23 | ('admin@admin.com', '325c162157dea106ce5bacc705c4929e4ec526a0290bfaba2dcbbf18103c7c2b', 'MKsiaw', 9, 'admin'); 24 | 25 | CREATE TABLE section ( 26 | id uuid primary key default gen_random_uuid(), 27 | title VARCHAR NOT NULL, 28 | description VARCHAR NOT NULL, 29 | stype INTEGER NOT NULL, 30 | suser uuid references ruser (id), 31 | created_time timestamp not null default current_timestamp, 32 | status smallint not null default 0, 33 | weight double precision not null default 0.0 -- new 34 | ); 35 | 36 | CREATE TABLE article ( 37 | id uuid primary key default gen_random_uuid(), 38 | title VARCHAR NOT NULL, 39 | raw_content VARCHAR NOT NULL, 40 | content VARCHAR NOT NULL, 41 | section_id uuid references section (id) not null, 42 | author_id uuid references ruser (id) not null, 43 | tags VARCHAR NOT NULL, 44 | extlink VARCHAR NOT NULL default '', 45 | stype INTEGER NOT NULL, 46 | created_time timestamp not null default current_timestamp, 47 | status smallint not null default 0, 48 | updated_time timestamp default now()::timestamp + '-1 year' 49 | ); 50 | 51 | CREATE TABLE comment ( 52 | id uuid primary key default gen_random_uuid(), 53 | raw_content VARCHAR NOT NULL, -- new 54 | content VARCHAR NOT NULL, 55 | article_id uuid references article (id) not null, 56 | author_id uuid references ruser (id) not null, 57 | created_time timestamp not null default current_timestamp, 58 | status smallint not null default 0 59 | ); 60 | 61 | CREATE TABLE articleweight ( 62 | id uuid primary key default gen_random_uuid(), 63 | section_id uuid references section (id) not null, 64 | article_id uuid references article (id) not null, 65 | weight double precision not null default 0.0, 66 | created_time timestamp not null default current_timestamp 67 | ); 68 | 69 | -------------------------------------------------------------------------------- /scripts/create_test_user.sh: -------------------------------------------------------------------------------- 1 | curl localhost:8081/register -X POST -d "account=mike&password=123&nickname=MikeTang" 2 | -------------------------------------------------------------------------------- /src/middleware.rs: -------------------------------------------------------------------------------- 1 | use sapper::{ 2 | Request, 3 | Error as SapperError 4 | }; 5 | use sapper_std::*; 6 | use crate::AppUser; 7 | use crate::envconfig; 8 | 9 | pub fn permission_need_login(req: &mut Request) -> Result<(), SapperError> { 10 | let (path, _) = req.uri(); 11 | if path.starts_with("/s/") || path.starts_with("/p/") 12 | { 13 | match get_ext!(req, AppUser) { 14 | Some(ref _user) => { 15 | // pass, nothing need to do here 16 | return Ok(()); 17 | }, 18 | None => { 19 | return res_400!("No permissions: need login.".to_string()); 20 | } 21 | } 22 | } 23 | else { 24 | Ok(()) 25 | } 26 | } 27 | 28 | pub fn permission_need_be_admin(req: &mut Request) -> Result<(), SapperError> { 29 | let (path, _) = req.uri(); 30 | if path.starts_with("/s/") || path.starts_with("/p/") 31 | { 32 | match get_ext!(req, AppUser) { 33 | Some(user) => { 34 | if user.role >= 9 { 35 | // pass, nothing need to do here 36 | return Ok(()); 37 | 38 | } 39 | else { 40 | return res_400!("No permissions: need be admin.".to_string()); 41 | } 42 | }, 43 | None => { 44 | return res_400!("No permissions: need login.".to_string()); 45 | } 46 | } 47 | } 48 | else { 49 | Ok(()) 50 | } 51 | } 52 | 53 | pub fn is_admin(req: &mut Request) -> bool { 54 | match get_ext!(req, AppUser) { 55 | Some(user) => { 56 | if user.role >= 9 { 57 | true 58 | } 59 | else { 60 | false 61 | } 62 | }, 63 | None => { 64 | false 65 | } 66 | } 67 | } 68 | 69 | pub fn check_cache_switch(req: &mut Request) -> bool { 70 | if envconfig::get_int_item("CACHE") == 1 && !is_admin(req) { 71 | true 72 | } 73 | else { 74 | false 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/page_forum.rs: -------------------------------------------------------------------------------- 1 | // include page modules 2 | pub mod index_page; 3 | pub mod user_page; 4 | pub mod section_page; 5 | pub mod article_page; 6 | pub mod comment_page; 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/page_forum/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/miketang84/forustm/6739092ff14ed611391d0cbcff65de4296db6d93/src/page_forum/.keep -------------------------------------------------------------------------------- /src/page_forum/article_page.rs: -------------------------------------------------------------------------------- 1 | use sapper::{ 2 | status, 3 | Request, 4 | Response, 5 | Result as SapperResult, 6 | Error as SapperError, 7 | Module as SapperModule, 8 | Router as SapperRouter}; 9 | use sapper_std::*; 10 | use uuid::Uuid; 11 | 12 | use crate::db; 13 | use crate::cache; 14 | use crate::envconfig; 15 | // introduce macros 16 | use sapper_std::res_html; 17 | use crate::{ 18 | AppWebContext, 19 | AppUser, 20 | TanIndexTx, 21 | TanQueryRx 22 | }; 23 | 24 | use crate::dataservice::article::{ 25 | Article, 26 | ArticleCreate, 27 | ArticleEdit 28 | }; 29 | use crate::dataservice::section::Section; 30 | use crate::dataservice::user::Ruser; 31 | 32 | use crate::util::markdown_render; 33 | use crate::middleware::{ 34 | permission_need_login, 35 | permission_need_be_admin, 36 | check_cache_switch 37 | }; 38 | 39 | struct CommentPaginator { 40 | total_comments: i32, 41 | total_page: i32, 42 | current_page: i32 43 | } 44 | 45 | use crate::tantivy_index::{ 46 | Doc2Index, 47 | TanAction, 48 | 49 | }; 50 | 51 | pub struct ArticlePage; 52 | 53 | impl ArticlePage { 54 | 55 | pub fn article_create_page(req: &mut Request) -> SapperResult { 56 | let mut web = get_ext_owned!(req, AppWebContext).unwrap(); 57 | let params = get_query_params!(req); 58 | 59 | let section_id = t_param_parse_default!(params, "section_id", Uuid, Uuid::default()); 60 | let sections = Section::forum_sections(); 61 | 62 | web.insert("section_id", §ion_id); 63 | web.insert("sections", §ions); 64 | 65 | 66 | res_html!("forum/new_article.html", web) 67 | } 68 | 69 | pub fn article_edit_page(req: &mut Request) -> SapperResult { 70 | let mut web = get_ext_owned!(req, AppWebContext).unwrap(); 71 | let params = get_query_params!(req); 72 | let id = t_param_parse!(params, "id", Uuid); 73 | 74 | // get article object 75 | let article_r = Article::get_by_id(id); 76 | if article_r.is_err() { 77 | return res_400!(format!("no this artile: {}", id)); 78 | } 79 | let article = article_r.unwrap(); 80 | 81 | let sections = Section::forum_sections(); 82 | 83 | web.insert("sections", §ions); 84 | web.insert("article", &article); 85 | 86 | res_html!("forum/edit_article.html", web) 87 | } 88 | 89 | pub fn article_delete_page(req: &mut Request) -> SapperResult { 90 | let mut web = get_ext_owned!(req, AppWebContext).unwrap(); 91 | let params = get_query_params!(req); 92 | let id = t_param_parse!(params, "id", Uuid); 93 | 94 | // get article object 95 | let article_r = Article::get_by_id(id); 96 | if article_r.is_err() { 97 | return res_400!(format!("no this artile: {}", id)); 98 | } 99 | let article = article_r.unwrap(); 100 | 101 | web.insert("article", &article); 102 | 103 | res_html!("forum/delete_article.html", web) 104 | } 105 | 106 | pub fn article_path_page(req: &mut Request) -> SapperResult { 107 | let params = get_path_params!(req); 108 | let id = t_param_parse!(params, "id", Uuid); 109 | 110 | res_redirect!(format!("/article?id={}", id)) 111 | } 112 | 113 | pub fn article_detail_page(req: &mut Request) -> SapperResult { 114 | let mut web = get_ext_owned!(req, AppWebContext).unwrap(); 115 | 116 | let params = get_query_params!(req); 117 | let id = t_param_parse!(params, "id", Uuid); 118 | let current_page = t_param_parse_default!(params, "current_page", i64, 1); 119 | let wx = t_param_parse_default!(params, "wx", i64, 0); 120 | 121 | let article_r = Article::get_by_id(id); 122 | if article_r.is_err() { 123 | return res_400!(format!("no this artile: {}", id)); 124 | } 125 | let article = article_r.unwrap(); 126 | 127 | let author_r = Ruser::get_user_by_id(article.author_id); 128 | if author_r.is_err() { 129 | return res_400!(format!("no this author: {}", article.author_id)); 130 | } 131 | let author = author_r.unwrap(); 132 | 133 | let mut is_author = false; 134 | let mut is_admin = false; 135 | let mut is_login = false; 136 | match get_ext!(req, AppUser) { 137 | Some(user) => { 138 | if article.author_id == user.id { 139 | is_author = true; 140 | } 141 | if user.role >= 9 { 142 | is_admin = true; 143 | } 144 | 145 | is_login = true; 146 | web.insert("is_login", &is_login); 147 | web.insert("user", &user); 148 | }, 149 | None => {} 150 | } 151 | 152 | let ncpp = envconfig::get_int_item("NUMBER_COMMENT_PER_PAGE"); 153 | // retrieve comments belongs to this article, and calculate its paginator 154 | let total_item = Article::get_comments_count_belong_to_this(id); 155 | let total_page = ((total_item -1) / ncpp) as i64 + 1; 156 | let comments = Article::get_comments_paging_belong_to_this(id, current_page); 157 | 158 | let viewtimes = Article::get_viewtimes(article.id); 159 | Article::increase_viewtimes(article.id); 160 | 161 | web.insert("article", &article); 162 | web.insert("author", &author); 163 | web.insert("comments", &comments); 164 | web.insert("current_page", ¤t_page); 165 | web.insert("total_item", &total_item); 166 | web.insert("total_page", &total_page); 167 | web.insert("is_author", &is_author); 168 | web.insert("is_admin", &is_admin); 169 | web.insert("viewtimes", &viewtimes); 170 | web.insert("wx", &wx); 171 | 172 | res_html!("forum/article.html", web) 173 | } 174 | 175 | pub fn article_create(req: &mut Request) -> SapperResult { 176 | let params = get_form_params!(req); 177 | let section_id = t_param_parse_default!(params, "section_id", Uuid, Uuid::default()); 178 | let title = t_param!(params, "title").to_owned(); 179 | let tags = t_param!(params, "tags").to_owned(); 180 | let extlink = t_param!(params, "extlink").to_owned(); 181 | let raw_content = t_param!(params, "raw_content"); 182 | let stype = t_param_parse_default!(params, "stype", i32, 0); 183 | 184 | let content = markdown_render(raw_content); 185 | let user = get_ext!(req, AppUser).unwrap(); 186 | 187 | let raw_content = raw_content.to_owned(); 188 | let article_create = ArticleCreate { 189 | title, 190 | tags, 191 | extlink, 192 | section_id, 193 | author_id: user.id, 194 | raw_content, 195 | content, 196 | stype, 197 | status: 0, 198 | }; 199 | 200 | match article_create.insert() { 201 | Ok(article) => { 202 | // add to tantivy index 203 | let ttv_index = get_ext!(req, TanIndexTx).unwrap(); 204 | let doc2index = Doc2Index { 205 | article_id: article.id.to_string(), 206 | created_time: article.created_time.timestamp().to_string(), 207 | title: article.title, 208 | content: article.raw_content 209 | }; 210 | ttv_index.send((TanAction::Add, "".to_string(), Some(doc2index))).unwrap(); 211 | 212 | res_redirect!(format!("/article?id={}", article.id)) 213 | }, 214 | Err(_) => { 215 | res_500!("article create error.") 216 | } 217 | } 218 | } 219 | 220 | pub fn article_edit(req: &mut Request) -> SapperResult { 221 | let params = get_form_params!(req); 222 | let id = t_param_parse!(params, "id", Uuid); 223 | let section_id = t_param_parse!(params, "section_id", Uuid); 224 | let title = t_param!(params, "title").to_owned(); 225 | let tags = t_param!(params, "tags").to_owned(); 226 | let extlink = t_param!(params, "extlink").to_owned(); 227 | let raw_content = t_param!(params, "raw_content"); 228 | 229 | let content = markdown_render(raw_content); 230 | let raw_content = raw_content.to_owned(); 231 | 232 | let article_edit = ArticleEdit { 233 | id, 234 | section_id, 235 | title, 236 | tags, 237 | extlink, 238 | raw_content, 239 | content, 240 | }; 241 | 242 | match article_edit.update() { 243 | Ok(article) => { 244 | let ttv_index = get_ext!(req, TanIndexTx).unwrap(); 245 | let doc2index = Doc2Index { 246 | article_id: article.id.to_string(), 247 | created_time: article.created_time.timestamp().to_string(), 248 | title: article.title, 249 | content: article.raw_content 250 | }; 251 | ttv_index.send((TanAction::Update, "".to_string(), Some(doc2index))).unwrap(); 252 | 253 | res_redirect!(format!("/article?id={}", article.id)) 254 | }, 255 | Err(_) => { 256 | res_500!("article edit error.") 257 | } 258 | } 259 | } 260 | 261 | pub fn article_delete(req: &mut Request) -> SapperResult { 262 | let params = get_form_params!(req); 263 | let article_id = t_param_parse!(params, "article_id", Uuid); 264 | let section_id = t_param_parse!(params, "section_id", Uuid); 265 | 266 | match Article::delete_by_id(article_id) { 267 | Ok(article) => { 268 | let ttv_index = get_ext!(req, TanIndexTx).unwrap(); 269 | ttv_index.send((TanAction::Delete, article.id.to_string(), None)).unwrap(); 270 | res_redirect!(format!("/section?id={}", section_id)) 271 | }, 272 | Err(_) => { 273 | res_500!("article delete error.") 274 | } 275 | } 276 | } 277 | 278 | pub fn article_delete_index(req: &mut Request) -> SapperResult { 279 | permission_need_be_admin(req)?; 280 | let params = get_query_params!(req); 281 | let article_id = t_param_parse!(params, "article_id", Uuid); 282 | 283 | let ttv_index = get_ext!(req, TanIndexTx).unwrap(); 284 | ttv_index.send((TanAction::Delete, article_id.to_string(), None)).unwrap(); 285 | res_redirect!("/") 286 | } 287 | 288 | // Blog Area 289 | pub fn blog_article_create_page(req: &mut Request) -> SapperResult { 290 | let mut web = get_ext_owned!(req, AppWebContext).unwrap(); 291 | let params = get_query_params!(req); 292 | 293 | let is_in_blog = true; 294 | web.insert("is_in_blog", &is_in_blog); 295 | 296 | res_html!("forum/new_article.html", web) 297 | } 298 | 299 | pub fn blog_article_edit_page(req: &mut Request) -> SapperResult { 300 | let mut web = get_ext_owned!(req, AppWebContext).unwrap(); 301 | let params = get_query_params!(req); 302 | let id = t_param_parse!(params, "id", Uuid); 303 | 304 | let is_in_blog = true; 305 | web.insert("is_in_blog", &is_in_blog); 306 | 307 | // get article object 308 | let article = Article::get_by_id(id); 309 | if article.is_err() { 310 | return res_400!(format!("no this artile: {}", id)); 311 | } 312 | let article = article.unwrap(); 313 | 314 | web.insert("article", &article); 315 | 316 | res_html!("forum/edit_article.html", web) 317 | } 318 | 319 | pub fn blog_article_create(req: &mut Request) -> SapperResult { 320 | let params = get_form_params!(req); 321 | 322 | let title = t_param!(params, "title").to_owned(); 323 | let tags = t_param!(params, "tags").to_owned(); 324 | let raw_content = t_param!(params, "raw_content"); 325 | let stype = t_param_parse_default!(params, "stype", i32, 1); 326 | let user = get_ext!(req, AppUser).unwrap(); 327 | let section_id = Section::get_by_suser(user.id).unwrap().id; 328 | 329 | let content = markdown_render(raw_content); 330 | let raw_content = raw_content.to_owned(); 331 | let article_create = ArticleCreate { 332 | title, 333 | tags, 334 | extlink: "".to_string(), 335 | section_id, 336 | author_id: user.id, 337 | raw_content, 338 | content, 339 | stype, 340 | status: 0, 341 | }; 342 | 343 | match article_create.insert() { 344 | Ok(article) => { 345 | res_redirect!(format!("/article?id={}", article.id)) 346 | }, 347 | Err(_) => { 348 | res_500!("article create error.") 349 | } 350 | } 351 | } 352 | 353 | pub fn blog_article_edit(req: &mut Request) -> SapperResult { 354 | 355 | let params = get_form_params!(req); 356 | let id = t_param_parse!(params, "id", Uuid); 357 | let title = t_param!(params, "title").to_owned(); 358 | let tags = t_param!(params, "tags").to_owned(); 359 | let raw_content = t_param!(params, "raw_content"); 360 | let user = get_ext!(req, AppUser).unwrap(); 361 | let section_id = Section::get_by_suser(user.id).unwrap().id; 362 | 363 | let content = markdown_render(raw_content); 364 | let raw_content = raw_content.to_owned(); 365 | 366 | let article_edit = ArticleEdit { 367 | id, 368 | section_id, 369 | title, 370 | tags, 371 | extlink: "".to_string(), 372 | raw_content, 373 | content, 374 | }; 375 | 376 | match article_edit.update() { 377 | Ok(article) => { 378 | res_redirect!(format!("/article?id={}", article.id)) 379 | }, 380 | Err(_) => { 381 | res_500!("article edit error.") 382 | } 383 | } 384 | } 385 | 386 | } 387 | 388 | 389 | impl SapperModule for ArticlePage { 390 | fn before(&self, req: &mut Request) -> SapperResult<()> { 391 | if check_cache_switch(req) { 392 | let (path, _) = req.uri(); 393 | if &path == "/article" { 394 | let params = get_query_params!(req); 395 | let article_id = t_param!(params, "id"); 396 | let current_page = t_param_parse_default!(params, "current_page", i64, 1); 397 | let part_key = article_id.to_string() + ":" + ¤t_page.to_string(); 398 | if cache::cache_is_valid("article", &part_key) { 399 | let cache_content = cache::cache_get("article", &part_key); 400 | return res_html_before!(cache_content); 401 | } 402 | } 403 | } 404 | 405 | permission_need_login(req)?; 406 | 407 | Ok(()) 408 | } 409 | 410 | fn after(&self, req: &Request, res: &mut Response) -> SapperResult<()> { 411 | let (path, _) = req.uri(); 412 | if &path == "/s/article/create" 413 | || &path == "/s/article/edit" 414 | || &path == "/s/article/delete" 415 | || &path == "/s/blogarticle/create" 416 | || &path == "/s/blogarticle/edit" { 417 | 418 | cache::cache_set_invalid("index", "index"); 419 | } 420 | 421 | // check other urls 422 | if &path == "/s/article/create" 423 | || &path == "/s/article/edit" 424 | || &path == "/s/article/delete" { 425 | 426 | let params = get_form_params!(req); 427 | let section_id = t_param_parse!(params, "section_id", Uuid); 428 | 429 | let napp = envconfig::get_int_item("NUMBER_ARTICLE_PER_PAGE"); 430 | let n = Section::get_articles_count_belong_to_this(section_id); 431 | let total_page = ((n -1) / napp) as i64 + 1; 432 | 433 | for i in 1..=total_page { 434 | let part_key = section_id.to_string() + ":" + &i.to_string(); 435 | cache::cache_set_invalid("section", &part_key); 436 | } 437 | } 438 | 439 | if &path == "/s/blogarticle/create" 440 | || &path == "/s/blogarticle/edit" { 441 | let user = get_ext!(req, AppUser).unwrap(); 442 | let section_id = Section::get_by_suser(user.id).unwrap().id; 443 | 444 | let napp = envconfig::get_int_item("NUMBER_ARTICLE_PER_PAGE"); 445 | let n = Section::get_articles_count_belong_to_this(section_id); 446 | let total_page = ((n -1) / napp) as i64 + 1; 447 | 448 | for i in 1..=total_page { 449 | let part_key = section_id.to_string() + ":" + &i.to_string(); 450 | cache::cache_set_invalid("section", &part_key); 451 | } 452 | } 453 | 454 | if &path == "/article" { 455 | let params = get_query_params!(req); 456 | let article_id = t_param!(params, "id"); 457 | let current_page = t_param_parse_default!(params, "current_page", i64, 1); 458 | let part_key = article_id.to_string() + ":" + ¤t_page.to_string(); 459 | if !cache::cache_is_valid("article", &part_key) { 460 | cache::cache_set("article", &part_key, res.body()); 461 | } 462 | } 463 | 464 | if &path == "/s/article/edit" 465 | || &path == "/s/blogarticle/edit" { 466 | let params = get_form_params!(req); 467 | let article_id = t_param!(params, "id"); 468 | 469 | cache::cache_set_invalid("article", article_id); 470 | } 471 | 472 | 473 | Ok(()) 474 | } 475 | 476 | fn router(&self, router: &mut SapperRouter) -> SapperResult<()> { 477 | router.get("/article", Self::article_detail_page); 478 | router.get("/article/:id", Self::article_path_page); 479 | 480 | router.get("/p/article/create", Self::article_create_page); 481 | router.get("/p/article/edit", Self::article_edit_page); 482 | router.get("/p/article/delete", Self::article_delete_page); 483 | router.post("/s/article/create", Self::article_create); 484 | router.post("/s/article/edit", Self::article_edit); 485 | router.post("/s/article/delete", Self::article_delete); 486 | router.get("/s/article/delete_index", Self::article_delete_index); 487 | 488 | router.get("/p/blogarticle/create", Self::blog_article_create_page); 489 | router.get("/p/blogarticle/edit", Self::blog_article_edit_page); 490 | router.post("/s/blogarticle/create", Self::blog_article_create); 491 | router.post("/s/blogarticle/edit", Self::blog_article_edit); 492 | 493 | Ok(()) 494 | } 495 | } 496 | -------------------------------------------------------------------------------- /src/page_forum/comment_page.rs: -------------------------------------------------------------------------------- 1 | use sapper::{ 2 | status, 3 | Request, 4 | Response, 5 | Result as SapperResult, 6 | Error as SapperError, 7 | Module as SapperModule, 8 | Router as SapperRouter}; 9 | use sapper_std::*; 10 | use uuid::Uuid; 11 | use chrono::*; 12 | 13 | use crate::db; 14 | use crate::cache; 15 | // introduce macros 16 | use sapper_std::res_html; 17 | use crate::{ 18 | AppWebContext, 19 | AppUser 20 | }; 21 | 22 | use crate::dataservice::article::{ 23 | Article, 24 | UpdateArticleUpdatedTime 25 | }; 26 | use crate::dataservice::comment::{ 27 | Comment, 28 | CommentCreate, 29 | CommentEdit 30 | }; 31 | 32 | use crate::util::markdown_render; 33 | use crate::middleware::permission_need_login; 34 | use crate::envconfig; 35 | 36 | 37 | pub struct CommentPage; 38 | 39 | impl CommentPage { 40 | 41 | pub fn comment_new_page(req: &mut Request) -> SapperResult { 42 | let mut web = get_ext_owned!(req, AppWebContext).unwrap(); 43 | let params = get_query_params!(req); 44 | let article_id = t_param_parse!(params, "article_id", Uuid); 45 | if t_has_param!(params, "reply_comment_id") { 46 | let reply_comment_id = t_param_parse!(params, "reply_comment_id", Uuid); 47 | match Comment::get_comment_with_author_name(reply_comment_id) { 48 | Ok(comment) => { 49 | web.insert("reply_comment", &comment); 50 | 51 | match Article::get_by_id(article_id) { 52 | Ok(article) => { 53 | web.insert("article", &article); 54 | return res_html!("forum/new_comment.html", web); 55 | }, 56 | Err(_) => { 57 | return res_500!("no this article."); 58 | } 59 | } 60 | }, 61 | Err(_) => { 62 | return res_500!("no this reply comment."); 63 | } 64 | } 65 | } 66 | else { 67 | match Article::get_by_id(article_id) { 68 | Ok(article) => { 69 | web.insert("article", &article); 70 | return res_html!("forum/new_comment.html", web); 71 | }, 72 | Err(_) => { 73 | return res_500!("no this article."); 74 | } 75 | } 76 | } 77 | } 78 | 79 | pub fn comment_edit_page(req: &mut Request) -> SapperResult { 80 | let mut web = get_ext_owned!(req, AppWebContext).unwrap(); 81 | let params = get_query_params!(req); 82 | let article_id = t_param_parse!(params, "article_id", Uuid); 83 | let comment_id = t_param_parse!(params, "comment_id", Uuid); 84 | 85 | match Article::get_by_id(article_id) { 86 | Ok(article) => { 87 | match Comment::get_by_id(comment_id) { 88 | Ok(comment) => { 89 | web.insert("article", &article); 90 | web.insert("comment", &comment); 91 | return res_html!("forum/edit_comment.html", web); 92 | }, 93 | Err(_) => { 94 | return res_500!("no this comment."); 95 | } 96 | } 97 | }, 98 | Err(_) => { 99 | return res_500!("no this article."); 100 | } 101 | } 102 | } 103 | 104 | pub fn comment_delete_page(req: &mut Request) -> SapperResult { 105 | let mut web = get_ext_owned!(req, AppWebContext).unwrap(); 106 | let params = get_query_params!(req); 107 | let comment_id = t_param_parse!(params, "id", Uuid); 108 | 109 | match Comment::get_by_id(comment_id) { 110 | Ok(comment) => { 111 | web.insert("comment", &comment); 112 | return res_html!("forum/delete_comment.html", web); 113 | }, 114 | Err(_) => { 115 | return res_500!("no this comment."); 116 | } 117 | } 118 | } 119 | 120 | pub fn comment_new(req: &mut Request) -> SapperResult { 121 | let params = get_form_params!(req); 122 | let article_id = t_param_parse!(params, "article_id", Uuid); 123 | let raw_content = t_param!(params, "raw_content"); 124 | 125 | let content = markdown_render(raw_content); 126 | let raw_content = raw_content.to_owned(); 127 | 128 | let user = get_ext!(req, AppUser).unwrap(); 129 | let author_id = user.id; 130 | 131 | let comment_create = CommentCreate { 132 | article_id, 133 | author_id, 134 | raw_content, 135 | content, 136 | status: 0 137 | }; 138 | 139 | match comment_create.insert() { 140 | Ok(comment) => { 141 | // update article updated_time 142 | let do_update = UpdateArticleUpdatedTime { 143 | id: comment.article_id, 144 | updated_time: Utc::now() 145 | }; 146 | 147 | let _ = do_update.update(); 148 | 149 | res_redirect!(format!("/article?id={}", article_id)) 150 | }, 151 | Err(_) => { 152 | res_500!("comment create error.") 153 | } 154 | } 155 | } 156 | 157 | pub fn comment_edit(req: &mut Request) -> SapperResult { 158 | let params = get_form_params!(req); 159 | let id = t_param_parse!(params, "id", Uuid); 160 | let article_id = t_param_parse!(params, "article_id", Uuid); 161 | let raw_content = t_param!(params, "raw_content"); 162 | 163 | let content = markdown_render(raw_content); 164 | let raw_content = raw_content.to_owned(); 165 | 166 | let comment_edit = CommentEdit { 167 | id, 168 | raw_content, 169 | content 170 | }; 171 | 172 | match comment_edit.update() { 173 | Ok(comment) => { 174 | res_redirect!(format!("/article?id={}", article_id)) 175 | }, 176 | Err(_) => { 177 | res_500!("comment edit error.") 178 | } 179 | } 180 | } 181 | 182 | pub fn comment_delete(req: &mut Request) -> SapperResult { 183 | let params = get_form_params!(req); 184 | let article_id = t_param_parse!(params, "article_id", Uuid); 185 | let comment_id = t_param_parse!(params, "comment_id", Uuid); 186 | 187 | match Comment::delete_by_id(comment_id) { 188 | Ok(comment) => { 189 | res_redirect!(format!("/article?id={}", article_id)) 190 | }, 191 | Err(_) => { 192 | res_500!("comment delete error.") 193 | } 194 | } 195 | } 196 | 197 | 198 | } 199 | 200 | 201 | impl SapperModule for CommentPage { 202 | fn before(&self, req: &mut Request) -> SapperResult<()> { 203 | permission_need_login(req)?; 204 | 205 | Ok(()) 206 | } 207 | 208 | fn after(&self, req: &Request, res: &mut Response) -> SapperResult<()> { 209 | let (path, _) = req.uri(); 210 | if &path == "/s/comment/new" 211 | || &path == "/s/comment/edit" 212 | || &path == "/s/comment/delete" { 213 | 214 | let params = get_form_params!(req); 215 | let article_id = t_param_parse!(params, "article_id", Uuid); 216 | 217 | let ncpp = envconfig::get_int_item("NUMBER_COMMENT_PER_PAGE"); 218 | let n = Article::get_comments_count_belong_to_this(article_id); 219 | let total_page = ((n -1) / ncpp) as i64 + 1; 220 | 221 | for i in 1..=total_page { 222 | let part_key = article_id.to_string() + ":" + &i.to_string(); 223 | cache::cache_set_invalid("article", &part_key); 224 | } 225 | 226 | } 227 | 228 | Ok(()) 229 | } 230 | 231 | fn router(&self, router: &mut SapperRouter) -> SapperResult<()> { 232 | router.get("/p/comment/new", Self::comment_new_page); 233 | router.get("/p/comment/edit", Self::comment_edit_page); 234 | router.get("/p/comment/delete", Self::comment_delete_page); 235 | router.post("/s/comment/new", Self::comment_new); 236 | router.post("/s/comment/edit", Self::comment_edit); 237 | router.post("/s/comment/delete", Self::comment_delete); 238 | 239 | Ok(()) 240 | } 241 | } 242 | -------------------------------------------------------------------------------- /src/page_forum/index_page.rs: -------------------------------------------------------------------------------- 1 | use sapper::{ 2 | status, 3 | Request, 4 | Response, 5 | Result as SapperResult, 6 | Error as SapperError, 7 | Module as SapperModule, 8 | Router as SapperRouter}; 9 | use sapper_std::*; 10 | use log::info; 11 | 12 | use crate::db; 13 | // introduce macros 14 | use sapper_std::res_html; 15 | use crate::{AppWebContext, AppUser}; 16 | use crate::cache; 17 | use crate::rss; 18 | 19 | use crate::envconfig; 20 | use crate::dataservice::article::Article; 21 | use crate::dataservice::section::Section; 22 | 23 | use crate::{TanIndexTx, TanQueryRx}; 24 | use crate::tantivy_index::{DocFromIndexOuter, Doc2Index, TanAction}; 25 | use crate::middleware::{ 26 | permission_need_be_admin, 27 | check_cache_switch 28 | }; 29 | 30 | pub struct IndexPage; 31 | 32 | impl IndexPage { 33 | 34 | pub fn index(req: &mut Request) -> SapperResult { 35 | let mut web = get_ext_owned!(req, AppWebContext).unwrap(); 36 | 37 | let napp = envconfig::get_int_item("NUMBER_ARTICLE_PER_PAGE"); 38 | let articles = Article::get_latest_articles(napp); 39 | 40 | let reply_articles = Article::get_latest_reply_articles(napp); 41 | 42 | let blog_articles = Article::get_latest_blog_articles(napp); 43 | 44 | // get all configured index displaying sections 45 | // and latest commented three articles 46 | let sections = Section::forum_sections(); 47 | 48 | web.insert("articles", &articles); 49 | web.insert("reply_articles", &reply_articles); 50 | web.insert("blog_articles", &blog_articles); 51 | web.insert("sections", §ions); 52 | 53 | res_html!("forum/index.html", web) 54 | } 55 | 56 | pub fn rss_xml(req: &mut Request) -> SapperResult { 57 | let rss_string = rss::make_rss_feed(); 58 | 59 | res_xml_string!(rss_string) 60 | } 61 | 62 | pub fn search_query_page(req: &mut Request) -> SapperResult { 63 | let mut web = get_ext_owned!(req, AppWebContext).unwrap(); 64 | 65 | let params = get_query_params!(req); 66 | let q = t_param_default!(params, "q", ""); 67 | 68 | let mut docs: Vec = Vec::new(); 69 | if q != "" { 70 | let tan_index = get_ext!(req, TanIndexTx).unwrap(); 71 | // send query directive 72 | tan_index.send((TanAction::Query, q.to_string(), None)).unwrap(); 73 | 74 | let tan_query = get_ext!(req, TanQueryRx).unwrap(); 75 | // block receiving 76 | docs = tan_query.recv().unwrap(); 77 | } 78 | 79 | web.insert("docs", &docs); 80 | web.insert("q", q); 81 | 82 | res_html!("forum/search_result.html", web) 83 | } 84 | 85 | pub fn search_query(req: &mut Request) -> SapperResult { 86 | let params = get_form_params!(req); 87 | let q = t_param!(params, "q"); 88 | 89 | res_redirect!(format!("/search?q={}", q)) 90 | } 91 | 92 | pub fn makeindex(req: &mut Request) -> SapperResult { 93 | permission_need_be_admin(req)?; 94 | 95 | let tan_index = get_ext!(req, TanIndexTx).unwrap(); 96 | 97 | let articles = Article::get_all_articles(); 98 | 99 | for article in articles { 100 | let doc2index = Doc2Index { 101 | article_id: article.id.to_string(), 102 | created_time: article.created_time.timestamp().to_string(), 103 | title: article.title, 104 | content: article.raw_content 105 | }; 106 | // send query directive 107 | tan_index.send((TanAction::Add, "".to_string(), Some(doc2index))).unwrap(); 108 | } 109 | 110 | info!("Make index test finished."); 111 | 112 | res_redirect!("/search") 113 | } 114 | 115 | pub fn acknowledgement(req: &mut Request) -> SapperResult { 116 | let mut web = get_ext_owned!(req, AppWebContext).unwrap(); 117 | 118 | res_html!("forum/acknowledgement.html", web) 119 | } 120 | 121 | pub fn latest_articles_paging(req: &mut Request) -> SapperResult { 122 | let mut web = get_ext_owned!(req, AppWebContext).unwrap(); 123 | let params = get_query_params!(req); 124 | 125 | let current_page = t_param_parse_default!(params, "current_page", i64, 1); 126 | 127 | let mut is_admin = false; 128 | let mut is_login = false; 129 | match get_ext!(req, AppUser) { 130 | Some(user) => { 131 | if user.role >= 9 { 132 | is_admin = true; 133 | } 134 | 135 | is_login = true; 136 | web.insert("is_login", &is_login); 137 | web.insert("user", &user); 138 | }, 139 | None => {} 140 | } 141 | 142 | let napp = envconfig::get_int_item("BIG_NUMBER_ARTICLE_PER_PAGE"); 143 | let total_item = Article::get_all_section_articles_count(); 144 | let total_page = ((total_item - 1) / napp) as i64 + 1; 145 | 146 | let articles = Article::get_latest_articles_paging(current_page-1, napp); 147 | 148 | web.insert("is_admin", &is_admin); 149 | web.insert("total_item", &total_item); 150 | web.insert("total_page", &total_page); 151 | web.insert("current_page", ¤t_page); 152 | web.insert("articles", &articles); 153 | web.insert("this_page_url", "latest_articles_paging"); 154 | web.insert("s_title", "Latest Articles"); 155 | 156 | res_html!("forum/article_list_paging.html", web) 157 | } 158 | 159 | pub fn latest_reply_articles_paging(req: &mut Request) -> SapperResult { 160 | let mut web = get_ext_owned!(req, AppWebContext).unwrap(); 161 | let params = get_query_params!(req); 162 | 163 | let current_page = t_param_parse_default!(params, "current_page", i64, 1); 164 | 165 | let mut is_admin = false; 166 | let mut is_login = false; 167 | match get_ext!(req, AppUser) { 168 | Some(user) => { 169 | if user.role >= 9 { 170 | is_admin = true; 171 | } 172 | 173 | is_login = true; 174 | web.insert("is_login", &is_login); 175 | web.insert("user", &user); 176 | }, 177 | None => {} 178 | } 179 | 180 | let napp = envconfig::get_int_item("BIG_NUMBER_ARTICLE_PER_PAGE"); 181 | let total_item = Article::get_all_section_articles_count(); 182 | let total_page = ((total_item - 1) / napp) as i64 + 1; 183 | 184 | let articles = Article::get_latest_reply_articles_paging(current_page-1, napp); 185 | 186 | web.insert("is_admin", &is_admin); 187 | web.insert("total_item", &total_item); 188 | web.insert("total_page", &total_page); 189 | web.insert("current_page", ¤t_page); 190 | web.insert("articles", &articles); 191 | web.insert("this_page_url", "latest_reply_articles_paging"); 192 | web.insert("s_title", "Latest Articles On Reply"); 193 | 194 | res_html!("forum/article_list_paging.html", web) 195 | } 196 | 197 | pub fn latest_blog_articles_paging(req: &mut Request) -> SapperResult { 198 | let mut web = get_ext_owned!(req, AppWebContext).unwrap(); 199 | let params = get_query_params!(req); 200 | 201 | let current_page = t_param_parse_default!(params, "current_page", i64, 1); 202 | 203 | let mut is_admin = false; 204 | let mut is_login = false; 205 | match get_ext!(req, AppUser) { 206 | Some(user) => { 207 | if user.role >= 9 { 208 | is_admin = true; 209 | } 210 | 211 | is_login = true; 212 | web.insert("is_login", &is_login); 213 | web.insert("user", &user); 214 | }, 215 | None => {} 216 | } 217 | 218 | let napp = envconfig::get_int_item("BIG_NUMBER_ARTICLE_PER_PAGE"); 219 | let total_item = Article::get_all_blog_articles_count(); 220 | let total_page = ((total_item - 1) / napp) as i64 + 1; 221 | 222 | let articles = Article::get_latest_blog_articles_paging(current_page-1, napp); 223 | 224 | web.insert("is_admin", &is_admin); 225 | web.insert("total_item", &total_item); 226 | web.insert("total_page", &total_page); 227 | web.insert("current_page", ¤t_page); 228 | web.insert("articles", &articles); 229 | web.insert("this_page_url", "latest_blog_articles_paging"); 230 | web.insert("s_title", "Latest Notes"); 231 | 232 | res_html!("forum/article_list_paging.html", web) 233 | } 234 | 235 | } 236 | 237 | 238 | impl SapperModule for IndexPage { 239 | fn before(&self, req: &mut Request) -> SapperResult<()> { 240 | let (path, _) = req.uri(); 241 | if check_cache_switch(req) { 242 | if &path == "/" { 243 | if cache::cache_is_valid("index", "index") { 244 | let cache_content = cache::cache_get("index", "index"); 245 | 246 | splog(req, status::Ok).unwrap(); 247 | return res_html_before!(cache_content); 248 | } 249 | } 250 | } 251 | 252 | Ok(()) 253 | } 254 | 255 | fn after(&self, req: &Request, res: &mut Response) -> SapperResult<()> { 256 | let (path, _) = req.uri(); 257 | if &path == "/" { 258 | if !cache::cache_is_valid("index", "index") { 259 | cache::cache_set("index", "index", res.body()); 260 | } 261 | } 262 | 263 | Ok(()) 264 | } 265 | 266 | 267 | fn router(&self, router: &mut SapperRouter) -> SapperResult<()> { 268 | router.get("/", Self::index); 269 | router.get("/latest_articles_paging", Self::latest_articles_paging); 270 | router.get("/latest_reply_articles_paging", Self::latest_reply_articles_paging); 271 | router.get("/latest_blog_articles_paging", Self::latest_blog_articles_paging); 272 | 273 | router.get("/rss", Self::rss_xml); 274 | router.get("/search", Self::search_query_page); 275 | router.post("/search", Self::search_query); 276 | router.get("/acknowledgement", Self::acknowledgement); 277 | 278 | // need to be limited call by admin only 279 | router.get("/makeindex", Self::makeindex); 280 | 281 | 282 | Ok(()) 283 | } 284 | } 285 | -------------------------------------------------------------------------------- /src/page_forum/section_page.rs: -------------------------------------------------------------------------------- 1 | use sapper::{ 2 | status, 3 | Request, 4 | Response, 5 | Result as SapperResult, 6 | Error as SapperError, 7 | Module as SapperModule, 8 | Router as SapperRouter}; 9 | use sapper_std::*; 10 | use uuid::Uuid; 11 | 12 | use crate::db; 13 | use crate::cache; 14 | // introduce macros 15 | use sapper_std::res_html; 16 | use crate::{ 17 | AppWebContext, 18 | AppUser 19 | }; 20 | 21 | use crate::dataservice::article::{ 22 | ArticleWeight, 23 | ArticleWeightCreate 24 | }; 25 | 26 | use crate::dataservice::section::{ 27 | Section, 28 | SectionNew, 29 | SectionEdit, 30 | UpdateSectionWeight 31 | }; 32 | 33 | use crate::middleware::{ 34 | permission_need_be_admin, 35 | permission_need_login, 36 | is_admin, 37 | check_cache_switch, 38 | }; 39 | use crate::envconfig; 40 | 41 | 42 | pub struct SectionPage; 43 | 44 | impl SectionPage { 45 | 46 | pub fn section_create_page(req: &mut Request) -> SapperResult { 47 | permission_need_be_admin(req)?; 48 | let mut web = get_ext_owned!(req, AppWebContext).unwrap(); 49 | 50 | res_html!("forum/new_section.html", web) 51 | } 52 | 53 | pub fn section_edit_page(req: &mut Request) -> SapperResult { 54 | let mut web = get_ext_owned!(req, AppWebContext).unwrap(); 55 | 56 | let (path, _) = req.uri(); 57 | if path == "/p/blogsection/edit" { 58 | let user = get_ext!(req, AppUser).unwrap(); 59 | match Section::get_by_suser(user.id) { 60 | Ok(section) => { 61 | web.insert("section", §ion); 62 | res_html!("forum/edit_section.html", web) 63 | }, 64 | Err(info) => { 65 | res_400!(info) 66 | } 67 | } 68 | } 69 | else { 70 | let params = get_query_params!(req); 71 | let section_id = t_param_parse!(params, "id", Uuid); 72 | 73 | if is_admin(req) { 74 | let section = Section::get_by_id(section_id).unwrap(); 75 | web.insert("section", §ion); 76 | res_html!("forum/edit_section.html", web) 77 | } 78 | else { 79 | let user = get_ext!(req, AppUser).unwrap(); 80 | match Section::get_by_suser(user.id) { 81 | Ok(section) => { 82 | if section.id == section_id { 83 | web.insert("section", §ion); 84 | res_html!("forum/edit_section.html", web) 85 | } 86 | else { 87 | res_400!("no permission.".to_string()) 88 | } 89 | }, 90 | Err(info) => { 91 | res_400!(info) 92 | } 93 | } 94 | } 95 | } 96 | } 97 | 98 | pub fn section_detail_page(req: &mut Request) -> SapperResult { 99 | let mut web = get_ext_owned!(req, AppWebContext).unwrap(); 100 | let params = get_query_params!(req); 101 | 102 | let (path, _) = req.uri(); 103 | let section_id = if path == "/blog_with_author" { 104 | let author_id = t_param_parse!(params, "author_id", Uuid); 105 | let section = Section::get_by_suser(author_id); 106 | if section.is_err() { 107 | return res_400!("no this section"); 108 | } 109 | let section = section.unwrap(); 110 | section.id 111 | } 112 | else { 113 | t_param_parse!(params, "id", Uuid) 114 | }; 115 | 116 | let current_page = t_param_parse_default!(params, "current_page", i64, 1); 117 | 118 | let section_result = Section::get_by_id(section_id); 119 | if section_result.is_err() { 120 | return res_400!("no this section"); 121 | } 122 | 123 | let section = section_result.unwrap(); 124 | let mut is_a_blog = false; 125 | if section.stype == 1 { 126 | is_a_blog = true; 127 | } 128 | let mut is_myown_blog = false; 129 | let mut is_admin = false; 130 | let mut is_login = false; 131 | match get_ext!(req, AppUser) { 132 | Some(user) => { 133 | if section.suser == Some(user.id) { 134 | is_myown_blog = true; 135 | } 136 | if user.role >= 9 { 137 | is_admin = true; 138 | } 139 | 140 | is_login = true; 141 | web.insert("is_login", &is_login); 142 | web.insert("user", &user); 143 | }, 144 | None => {} 145 | } 146 | 147 | let napp = envconfig::get_int_item("NUMBER_ARTICLE_PER_PAGE"); 148 | let total_item = Section::get_articles_count_belong_to_this(section.id); 149 | let total_page = ((total_item - 1) / napp) as i64 + 1; 150 | 151 | let articles = Section::get_articles_paging_belong_to_this(section.id, current_page); 152 | 153 | web.insert("section", §ion); 154 | web.insert("is_a_blog", &is_a_blog); 155 | web.insert("is_myown_blog", &is_myown_blog); 156 | web.insert("is_admin", &is_admin); 157 | web.insert("total_item", &total_item); 158 | web.insert("total_page", &total_page); 159 | web.insert("current_page", ¤t_page); 160 | web.insert("articles", &articles); 161 | 162 | res_html!("forum/section.html", web) 163 | } 164 | 165 | 166 | 167 | pub fn section_create(req: &mut Request) -> SapperResult { 168 | permission_need_be_admin(req)?; 169 | let params = get_form_params!(req); 170 | let title = t_param!(params, "title").to_owned(); 171 | let description = t_param!(params, "description").to_owned(); 172 | 173 | let section_new = SectionNew { 174 | title, 175 | description 176 | }; 177 | 178 | match section_new.create() { 179 | Ok(section) => { 180 | res_redirect!(format!("/section?id={}", section.id)) 181 | }, 182 | Err(_) => { 183 | res_500!("section create error.") 184 | } 185 | } 186 | } 187 | 188 | pub fn section_edit(req: &mut Request) -> SapperResult { 189 | let params = get_form_params!(req); 190 | let id = t_param_parse!(params, "id", Uuid); 191 | let title = t_param!(params, "title").to_owned(); 192 | let description = t_param!(params, "description").to_owned(); 193 | 194 | let section_edit = SectionEdit { 195 | id, 196 | title, 197 | description 198 | }; 199 | 200 | match section_edit.update() { 201 | Ok(section) => { 202 | res_redirect!(format!("/section?id={}", section.id)) 203 | }, 204 | Err(_) => { 205 | res_500!("section edit error.") 206 | } 207 | } 208 | } 209 | 210 | pub fn section_rearrange_page(req: &mut Request) -> SapperResult { 211 | permission_need_be_admin(req)?; 212 | let mut web = get_ext_owned!(req, AppWebContext).unwrap(); 213 | 214 | let sections = Section::forum_sections(); 215 | 216 | web.insert("sections", §ions); 217 | 218 | res_html!("forum/arrange_sections.html", web) 219 | } 220 | 221 | 222 | pub fn section_rearrange(req: &mut Request) -> SapperResult { 223 | permission_need_be_admin(req)?; 224 | let mut web = get_ext_owned!(req, AppWebContext).unwrap(); 225 | let params = get_form_params!(req); 226 | let order = t_arr_param!(params, "order"); 227 | 228 | // print order 229 | let sections = Section::forum_sections(); 230 | for (i, section) in sections.iter().enumerate() { 231 | let update_section_weight = UpdateSectionWeight { 232 | id: section.id, 233 | weight: order[i].parse::().unwrap() 234 | }; 235 | update_section_weight.update().unwrap(); 236 | } 237 | 238 | res_redirect!("/p/section/rearrange") 239 | } 240 | 241 | pub fn section_manage_view_list_page(req: &mut Request) -> SapperResult { 242 | let mut web = get_ext_owned!(req, AppWebContext).unwrap(); 243 | 244 | let sections = Section::all_forum_sections(); 245 | 246 | web.insert("sections", §ions); 247 | 248 | res_html!("forum/manage_section_view.html", web) 249 | } 250 | 251 | pub fn section_manage_view_page(req: &mut Request) -> SapperResult { 252 | let mut web = get_ext_owned!(req, AppWebContext).unwrap(); 253 | let params = get_query_params!(req); 254 | let section_id = t_param_parse!(params, "id", Uuid); 255 | 256 | let section = Section::get_by_id(section_id).unwrap(); 257 | let articles = Section::get_specified_articles(section_id); 258 | 259 | web.insert("section", §ion); 260 | web.insert("articles", &articles); 261 | 262 | res_html!("forum/manage_section_view_articles.html", web) 263 | } 264 | 265 | pub fn section_manage_article_view_delete(req: &mut Request) -> SapperResult { 266 | let params = get_query_params!(req); 267 | let article_weight_id = t_param_parse!(params, "id", Uuid); 268 | 269 | let aw = ArticleWeight::delete_by_id(article_weight_id).unwrap(); 270 | 271 | res_redirect!(format!("/p/section/manage_view?id={}", aw.section_id)) 272 | } 273 | 274 | pub fn section_manage_article_view_add(req: &mut Request) -> SapperResult { 275 | let params = get_form_params!(req); 276 | let section_id = t_param_parse!(params, "section_id", Uuid); 277 | let article_id = t_param_parse!(params, "article_id", Uuid); 278 | let weight = t_param_parse!(params, "weight", f64); 279 | 280 | let aw_new = ArticleWeightCreate { 281 | section_id, 282 | article_id, 283 | weight, 284 | }; 285 | 286 | let aw = aw_new.insert().unwrap(); 287 | 288 | res_redirect!(format!("/p/section/manage_view?id={}", section_id)) 289 | } 290 | 291 | pub fn admin_section(req: &mut Request) -> SapperResult { 292 | let mut web = get_ext_owned!(req, AppWebContext).unwrap(); 293 | 294 | res_html!("forum/admin_landing_page.html", web) 295 | } 296 | 297 | } 298 | 299 | 300 | impl SapperModule for SectionPage { 301 | fn before(&self, req: &mut Request) -> SapperResult<()> { 302 | // check cache 303 | if check_cache_switch(req) { 304 | let (path, _) = req.uri(); 305 | if &path == "/section" || &path == "/blog" { 306 | let params = get_query_params!(req); 307 | let section_id = t_param!(params, "id"); 308 | let current_page = t_param_parse_default!(params, "current_page", i64, 1); 309 | let part_key = section_id.to_string() + ":" + ¤t_page.to_string(); 310 | if cache::cache_is_valid("section", &part_key) { 311 | let cache_content = cache::cache_get("section", &part_key); 312 | return res_html_before!(cache_content); 313 | } 314 | } 315 | } 316 | 317 | // permission 318 | permission_need_login(req)?; 319 | 320 | Ok(()) 321 | } 322 | 323 | fn after(&self, req: &Request, res: &mut Response) -> SapperResult<()> { 324 | let (path, _) = req.uri(); 325 | if &path == "/s/section/create" 326 | || &path == "/s/section/edit" 327 | || &path == "/s/section/rearrange" { 328 | 329 | cache::cache_set_invalid("index", "index"); 330 | } 331 | 332 | // check other url 333 | if &path == "/section" || &path == "/blog" { 334 | let params = get_query_params!(req); 335 | let section_id = t_param!(params, "id"); 336 | let current_page = t_param_parse_default!(params, "current_page", i64, 1); 337 | let part_key = section_id.to_string() + ":" + ¤t_page.to_string(); 338 | if !cache::cache_is_valid("section", &part_key) { 339 | cache::cache_set("section", &part_key, res.body()); 340 | } 341 | } 342 | 343 | if &path == "/s/section/edit" { 344 | let params = get_form_params!(req); 345 | let section_id = t_param!(params, "id"); 346 | cache::cache_set_invalid("section", section_id); 347 | } 348 | 349 | Ok(()) 350 | } 351 | 352 | fn router(&self, router: &mut SapperRouter) -> SapperResult<()> { 353 | router.get("/section", Self::section_detail_page); 354 | router.get("/blog", Self::section_detail_page); 355 | router.get("/blog_with_author", Self::section_detail_page); 356 | 357 | router.get("/p/section/create", Self::section_create_page); 358 | router.get("/p/section/edit", Self::section_edit_page); 359 | router.get("/p/blogsection/edit", Self::section_edit_page); 360 | router.post("/s/section/create", Self::section_create); 361 | router.post("/s/section/edit", Self::section_edit); 362 | 363 | router.get("/p/section/rearrange", Self::section_rearrange_page); 364 | router.post("/s/section/rearrange", Self::section_rearrange); 365 | 366 | router.get("/admin_section", Self::admin_section); 367 | router.get("/p/section/manage_view_list", Self::section_manage_view_list_page); 368 | router.get("/p/section/manage_view", Self::section_manage_view_page); 369 | router.get("/s/section/manage_article_view/delete", Self::section_manage_article_view_delete); 370 | router.post("/s/section/manage_article_view/add", Self::section_manage_article_view_add); 371 | 372 | 373 | Ok(()) 374 | } 375 | } 376 | -------------------------------------------------------------------------------- /src/page_forum/user_page.rs: -------------------------------------------------------------------------------- 1 | use sapper::{ 2 | Request, 3 | Response, 4 | Result as SapperResult, 5 | Error as SapperError, 6 | Module as SapperModule, 7 | Router as SapperRouter}; 8 | use sapper_std::*; 9 | use uuid::Uuid; 10 | 11 | use crate::db; 12 | use crate::github_utils::{ 13 | get_github_token, 14 | get_github_user_info, 15 | }; 16 | 17 | use crate::envconfig; 18 | use crate::util::make_pwd_encode; 19 | use crate::util::random_string; 20 | use crate::middleware::permission_need_login; 21 | 22 | // introduce macros 23 | use crate::{ 24 | AppWebContext, 25 | AppUser 26 | }; 27 | 28 | use crate::dataservice::user::{ 29 | Ruser, 30 | UserLogin, 31 | UserSignUp, 32 | GithubUserInfo, 33 | UpdateUserNickname, 34 | UserChangePassword, 35 | }; 36 | 37 | use crate::dataservice::article::{ 38 | Article 39 | }; 40 | 41 | pub struct UserPage; 42 | 43 | impl UserPage { 44 | 45 | pub fn page_login_with3rd(req: &mut Request) -> SapperResult { 46 | let mut web = get_ext_owned!(req, AppWebContext).unwrap(); 47 | 48 | let client_id = envconfig::get_str_item("GITHUB_APP_CLIENT_ID"); 49 | web.insert("client_id", &client_id); 50 | 51 | res_html!("forum/login_with3rd.html", web) 52 | } 53 | 54 | pub fn page_login_with_admin(req: &mut Request) -> SapperResult { 55 | let web = get_ext_owned!(req, AppWebContext).unwrap(); 56 | 57 | res_html!("forum/login_with_admin.html", web) 58 | } 59 | 60 | pub fn account(req: &mut Request) -> SapperResult { 61 | let mut web = get_ext_owned!(req, AppWebContext).unwrap(); 62 | match get_ext!(req, AppUser) { 63 | Some(user) => { 64 | web.insert("user", &user); 65 | return res_html!("forum/account.html", web); 66 | }, 67 | None => { 68 | let client_id = envconfig::get_str_item("GITHUB_APP_CLIENT_ID"); 69 | web.insert("client_id", &client_id); 70 | 71 | return res_html!("forum/login_with3rd.html", web); 72 | } 73 | } 74 | } 75 | 76 | pub fn user_register(req: &mut Request) -> SapperResult { 77 | 78 | let params = get_form_params!(req); 79 | let account = t_param!(params, "account").to_owned(); 80 | let password = t_param!(params, "password").to_owned(); 81 | let nickname = t_param!(params, "nickname").to_owned(); 82 | 83 | let user_signup = UserSignUp { 84 | account, 85 | password, 86 | nickname 87 | }; 88 | 89 | // TODO: need to check the result of this call 90 | let _ = user_signup.sign_up(None); 91 | 92 | // redirect to login with account and password 93 | res_redirect!("/login_with_admin") 94 | } 95 | 96 | pub fn user_login(req: &mut Request) -> SapperResult { 97 | 98 | let params = get_form_params!(req); 99 | let account = t_param!(params, "account").to_owned(); 100 | let password = t_param!(params, "password").to_owned(); 101 | 102 | let user_login = UserLogin { 103 | account, 104 | password 105 | }; 106 | 107 | // use dataservice logic 108 | let cookie_r = user_login.verify_login(); 109 | if cookie_r.is_err() { 110 | return res_redirect!("/login_with_admin"); 111 | } 112 | let cookie = cookie_r.unwrap(); 113 | 114 | let mut response = Response::new(); 115 | let _ = set_cookie( 116 | &mut response, 117 | "rusoda_session".to_string(), 118 | cookie, 119 | None, 120 | Some("/".to_string()), 121 | None, 122 | Some(60*24*3600), 123 | ); 124 | 125 | // redirect to index 126 | set_response_redirect!(response, "/"); 127 | 128 | Ok(response) 129 | } 130 | 131 | pub fn user_login_with_github(req: &mut Request) -> SapperResult { 132 | 133 | let params = get_query_params!(req); 134 | let code = t_param!(params, "code"); 135 | 136 | let client_id = envconfig::get_str_item("GITHUB_APP_CLIENT_ID"); 137 | let client_secret = envconfig::get_str_item("GITHUB_APP_CLIENT_SECRET"); 138 | 139 | let token_r = get_github_token(&code, client_id, client_secret); 140 | if token_r.is_err() { 141 | return res_400!("get github token code err"); 142 | } 143 | let access_token = token_r.unwrap(); 144 | let github_user_info: GithubUserInfo = get_github_user_info(&access_token).unwrap(); 145 | 146 | let account = github_user_info.account; 147 | let password; 148 | let cookie; 149 | 150 | 151 | match Ruser::get_user_by_account(&account) { 152 | Ok(user) => { 153 | // already exists 154 | password = user.password; 155 | // next step auto login 156 | let user_login = UserLogin { 157 | account, 158 | password 159 | }; 160 | cookie = user_login.verify_login_with_rawpwd().unwrap(); 161 | }, 162 | Err(_) => { 163 | password = random_string(8); 164 | // register it 165 | let user_signup = UserSignUp { 166 | account: account.clone(), 167 | password: password.clone(), 168 | nickname: account.clone(), 169 | }; 170 | // TODO: check the result 171 | let _ = user_signup.sign_up(Some(github_user_info.github_address)); 172 | // next step auto login 173 | let user_login = UserLogin { 174 | account, 175 | password 176 | }; 177 | cookie = user_login.verify_login().unwrap(); 178 | } 179 | } 180 | 181 | let mut response = Response::new(); 182 | let _ = set_cookie( 183 | &mut response, 184 | "rusoda_session".to_string(), 185 | cookie, 186 | None, 187 | Some("/".to_string()), 188 | None, 189 | Some(60*24*3600), 190 | ); 191 | 192 | // redirect to index 193 | set_response_redirect!(response, "/"); 194 | 195 | Ok(response) 196 | } 197 | 198 | 199 | pub fn user_signout(req: &mut Request) -> SapperResult { 200 | match get_ext!(req, SessionVal) { 201 | Some(cookie) => { 202 | let _ = Ruser::sign_out(cookie); 203 | }, 204 | None => {} 205 | } 206 | 207 | res_redirect!("/") 208 | } 209 | 210 | pub fn user_modifynickname_page(req: &mut Request) -> SapperResult { 211 | let web = get_ext_owned!(req, AppWebContext).unwrap(); 212 | 213 | res_html!("forum/user_modifynickname_page.html", web) 214 | } 215 | 216 | pub fn user_modifynickname(req: &mut Request) -> SapperResult { 217 | let web = get_ext_owned!(req, AppWebContext).unwrap(); 218 | let params = get_form_params!(req); 219 | let nickname = t_param!(params, "nickname").to_owned(); 220 | 221 | let user = get_ext!(req, AppUser).unwrap(); 222 | let id = user.id; 223 | 224 | let update_user_nickname = UpdateUserNickname { 225 | id, 226 | nickname 227 | }; 228 | 229 | update_user_nickname.update().unwrap(); 230 | 231 | res_redirect!("/account") 232 | } 233 | 234 | pub fn user_changepassword_page(req: &mut Request) -> SapperResult { 235 | let web = get_ext_owned!(req, AppWebContext).unwrap(); 236 | 237 | res_html!("forum/user_change_pwd_page.html", web) 238 | } 239 | 240 | pub fn user_changepassword(req: &mut Request) -> SapperResult { 241 | let web = get_ext_owned!(req, AppWebContext).unwrap(); 242 | let params = get_form_params!(req); 243 | let old_pwd = t_param!(params, "old_pwd"); 244 | let new_pwd = t_param!(params, "new_pwd"); 245 | 246 | let user = get_ext!(req, AppUser).unwrap(); 247 | let id = user.id; 248 | 249 | // check password equality 250 | if user.password == make_pwd_encode(old_pwd, &user.salt) { 251 | let user_change_pwd = UserChangePassword { 252 | id, 253 | password: make_pwd_encode(new_pwd, &user.salt) 254 | }; 255 | 256 | let _ = user_change_pwd.change(); 257 | 258 | res_redirect!("/account") 259 | } 260 | else { 261 | res_400!("not corrent old password.") 262 | } 263 | } 264 | 265 | pub fn user_my_articles_page(req: &mut Request) -> SapperResult { 266 | let mut web = get_ext_owned!(req, AppWebContext).unwrap(); 267 | let params = get_query_params!(req); 268 | 269 | let current_page = t_param_parse_default!(params, "current_page", i64, 1); 270 | 271 | let mut is_admin = false; 272 | let mut is_login = false; 273 | let mut user_id: Uuid = Default::default(); 274 | match get_ext!(req, AppUser) { 275 | Some(user) => { 276 | user_id = user.id; 277 | 278 | if user.role >= 9 { 279 | is_admin = true; 280 | } 281 | 282 | is_login = true; 283 | web.insert("is_login", &is_login); 284 | web.insert("user", &user); 285 | }, 286 | None => {} 287 | } 288 | 289 | let napp = envconfig::get_int_item("BIG_NUMBER_ARTICLE_PER_PAGE"); 290 | let total_item = Article::get_all_articles_count_by_author(user_id); 291 | let total_page = ((total_item - 1) / napp) as i64 + 1; 292 | 293 | let articles = Article::get_latest_articles_paging_by_author(user_id, current_page-1, napp); 294 | 295 | web.insert("is_admin", &is_admin); 296 | web.insert("total_item", &total_item); 297 | web.insert("total_page", &total_page); 298 | web.insert("current_page", ¤t_page); 299 | web.insert("articles", &articles); 300 | web.insert("this_page_url", "p/user/my_articles"); 301 | web.insert("s_title", "User's Articles"); 302 | 303 | res_html!("forum/article_list_paging.html", web) 304 | } 305 | 306 | 307 | } 308 | 309 | 310 | impl SapperModule for UserPage { 311 | fn before(&self, req: &mut Request) -> SapperResult<()> { 312 | permission_need_login(req)?; 313 | 314 | Ok(()) 315 | } 316 | 317 | fn router(&self, router: &mut SapperRouter) -> SapperResult<()> { 318 | router.get("/login_with3rd", Self::page_login_with3rd); 319 | router.get("/login_with_admin", Self::page_login_with_admin); 320 | router.get("/account", Self::account); 321 | router.get("/signout", Self::user_signout); 322 | 323 | 324 | router.post("/register", Self::user_register); 325 | router.post("/login", Self::user_login); 326 | 327 | router.get("/p/user/modifynickname", Self::user_modifynickname_page); 328 | router.post("/s/user/modifynickname", Self::user_modifynickname); 329 | 330 | router.get("/p/user/changepassword", Self::user_changepassword_page); 331 | router.post("/s/user/changepassword", Self::user_changepassword); 332 | 333 | router.get("/p/user/my_articles", Self::user_my_articles_page); 334 | 335 | 336 | // this url will be called by remote github oauth2 server 337 | router.get("/api/v1/login_with_github", Self::user_login_with_github); 338 | 339 | 340 | Ok(()) 341 | } 342 | } 343 | -------------------------------------------------------------------------------- /src/page_forum_bin.rs: -------------------------------------------------------------------------------- 1 | #[macro_use] extern crate log; 2 | #[macro_use] 3 | extern crate serde_derive; 4 | use std::{env, thread}; 5 | use env_logger; 6 | use dotenv::dotenv; 7 | use rusoda; 8 | use serde; 9 | use serde_json; 10 | use crossbeam::channel; 11 | 12 | use std::sync::{ 13 | Arc, 14 | Mutex, 15 | }; 16 | 17 | //#[macro_use] extern crate sapper_std; 18 | use sapper::{ 19 | App as SapperApp, 20 | Armor as SapperArmor, 21 | Result as SapperResult, 22 | Request, 23 | Response, 24 | Key 25 | }; 26 | use sapper_std::*; 27 | 28 | use rusoda::envconfig; 29 | use rusoda::db; 30 | use rusoda::cache; 31 | use rusoda::dataservice; 32 | use rusoda::util; 33 | use rusoda::github_utils; 34 | use rusoda::i18n; 35 | use rusoda::web_filters; 36 | use rusoda::rss; 37 | 38 | mod middleware; 39 | mod tantivy_index; 40 | 41 | // include page modules 42 | mod page_forum; 43 | 44 | use self::dataservice::user::Ruser; 45 | use self::tantivy_index::{ 46 | DocFromIndexOuter, TanAction, Doc2Index, 47 | }; 48 | 49 | 50 | 51 | pub struct AppWebContext; 52 | impl Key for AppWebContext { 53 | type Value = WebContext; 54 | } 55 | 56 | pub struct AppUser; 57 | impl Key for AppUser { 58 | type Value = Ruser; 59 | } 60 | 61 | pub struct TanIndexTx; 62 | impl Key for TanIndexTx { 63 | type Value = channel::Sender<(TanAction, String, Option)>; 64 | } 65 | pub struct TanQueryRx; 66 | impl Key for TanQueryRx { 67 | type Value = channel::Receiver>; 68 | } 69 | 70 | 71 | // define global smock 72 | struct PageForum; 73 | 74 | impl SapperArmor for PageForum { 75 | fn before(&self, req: &mut Request) -> SapperResult<()> { 76 | // define cookie prefix 77 | sapper_std::init(req, Some("rusoda_session"))?; 78 | // init web instance state 79 | let mut web = WebContext::new(); 80 | // we can add something to web 81 | match req.ext().get::() { 82 | Some(cookie) => { 83 | // using this cookie to retreive user instance 84 | match Ruser::get_user_by_cookie(&cookie) { 85 | Ok(user) => { 86 | if user.status == 0 { 87 | web.insert("user", &user); 88 | req.ext_mut().insert::(user); 89 | } 90 | }, 91 | Err(_) => {} 92 | } 93 | }, 94 | None => {} 95 | } 96 | 97 | // insert it to req 98 | req.ext_mut().insert::(web); 99 | 100 | Ok(()) 101 | } 102 | 103 | fn after(&self, req: &Request, res: &mut Response) -> SapperResult<()> { 104 | sapper_std::finish(req, res)?; 105 | Ok(()) 106 | } 107 | } 108 | 109 | fn main () { 110 | env_logger::init(); 111 | dotenv().ok(); 112 | // 113 | web_filters::register_web_filters(); 114 | 115 | // create first pair channel: send directive 116 | let (tan_index_tx, tan_index_rx) = channel::unbounded::<(TanAction, String, Option)>(); 117 | // create query result pair channel 118 | let (tan_query_tx, tan_query_rx) = channel::unbounded::>(); 119 | 120 | tantivy_index::run_tantivy(tan_index_rx, tan_query_tx); 121 | 122 | let addr = env::var("BINDADDR").expect("DBURL must be set"); 123 | let port = env::var("BINDPORT").expect("REDISURL must be set").parse::().unwrap(); 124 | let mut app = SapperApp::new(); 125 | app.address(&addr) 126 | .port(port) 127 | .init_global(Box::new(move |req: &mut Request| { 128 | req.ext_mut().insert::(tan_index_tx.clone()); 129 | req.ext_mut().insert::(tan_query_rx.clone()); 130 | 131 | Ok(()) 132 | })) 133 | .with_armor(Box::new(PageForum)) 134 | .add_module(Box::new(page_forum::index_page::IndexPage)) 135 | .add_module(Box::new(page_forum::user_page::UserPage)) 136 | .add_module(Box::new(page_forum::section_page::SectionPage)) 137 | .add_module(Box::new(page_forum::article_page::ArticlePage)) 138 | .add_module(Box::new(page_forum::comment_page::CommentPage)) 139 | .static_file_service(true); 140 | 141 | println!("Start listen on http://{}:{}", addr, port); 142 | app.run_http(); 143 | 144 | } 145 | -------------------------------------------------------------------------------- /src/tantivy_index.rs: -------------------------------------------------------------------------------- 1 | use cang_jie::{CangJieTokenizer, TokenizerOption, CANG_JIE}; 2 | use jieba_rs::Jieba; 3 | use tantivy::{collector::TopDocs, doc, query::QueryParser, schema::*, Index, IndexReader, IndexWriter, Searcher, Document, ReloadPolicy}; 4 | use tantivy::directory::MmapDirectory; 5 | use std::{collections::HashSet, io, iter::FromIterator, sync::Arc}; 6 | use std::path::Path; 7 | use serde::{Serialize, Deserialize}; 8 | use serde_json; 9 | use log::info; 10 | use uuid::Uuid; 11 | use chrono::{DateTime, Utc, NaiveDateTime}; 12 | use crossbeam::channel::{Sender, Receiver}; 13 | use std::thread; 14 | 15 | #[derive(Debug)] 16 | pub struct Doc2Index { 17 | pub article_id: String, 18 | pub created_time: String, 19 | pub title: String, 20 | pub content: String, 21 | } 22 | 23 | #[derive(Debug, Serialize, Deserialize)] 24 | pub struct DocFromIndex { 25 | pub article_id: Vec, 26 | pub title: Vec, 27 | pub created_time: Vec 28 | } 29 | 30 | #[derive(Debug, Serialize, Deserialize)] 31 | pub struct DocFromIndexOuter { 32 | pub article_id: Uuid, 33 | pub title: String, 34 | pub created_time: DateTime 35 | } 36 | 37 | pub struct TantivyIndex { 38 | // pub index: Index, 39 | pub schema: Schema, 40 | pub reader: IndexReader, 41 | pub writer: IndexWriter, 42 | pub query_parser: QueryParser 43 | } 44 | 45 | pub enum TanAction { 46 | Add, 47 | Update, 48 | Delete, 49 | Query 50 | } 51 | 52 | 53 | 54 | pub fn init() -> tantivy::Result { 55 | let mut schema_builder = SchemaBuilder::default(); 56 | 57 | let text_indexing = TextFieldIndexing::default() 58 | .set_tokenizer(CANG_JIE) // Set custom tokenizer 59 | .set_index_option(IndexRecordOption::WithFreqsAndPositions); 60 | let text_options = TextOptions::default() 61 | .set_indexing_options(text_indexing.clone()) 62 | .set_stored(); 63 | let text_options_nostored = TextOptions::default() 64 | .set_indexing_options(text_indexing); 65 | 66 | schema_builder.add_text_field("article_id", STRING | STORED); 67 | schema_builder.add_text_field("created_time", STRING | STORED); 68 | schema_builder.add_text_field("title", text_options); 69 | schema_builder.add_text_field("content", text_options_nostored); 70 | let schema = schema_builder.build(); 71 | 72 | let index = Index::open_or_create(MmapDirectory::open(Path::new("search_index/")).unwrap(), schema.clone())?; 73 | // let index = Index::open(MmapDirectory::open(Path::new("search_index/")).unwrap())?; 74 | index.tokenizers().register(CANG_JIE, tokenizer()); // Build cang-jie Tokenizer 75 | 76 | let writer = index.writer(50 * 1024 * 1024)?; 77 | 78 | let title = schema.get_field("title").unwrap(); 79 | let content = schema.get_field("content").unwrap(); 80 | 81 | let query_parser = QueryParser::for_index(&index, vec![title, content]); 82 | 83 | let reader = index 84 | .reader_builder() 85 | .reload_policy(ReloadPolicy::OnCommit) 86 | .try_into()?; 87 | 88 | Ok(TantivyIndex { 89 | schema: index.schema(), 90 | reader, 91 | writer, 92 | query_parser 93 | }) 94 | } 95 | 96 | impl TantivyIndex { 97 | 98 | pub fn add_doc(&mut self, doc: Doc2Index) -> tantivy::Result<()> { 99 | let schema = &self.schema; 100 | 101 | let article_id = schema.get_field("article_id").unwrap(); 102 | let created_time = schema.get_field("created_time").unwrap(); 103 | let title = schema.get_field("title").unwrap(); 104 | let content = schema.get_field("content").unwrap(); 105 | 106 | let mut a_doc = Document::default(); 107 | a_doc.add_text(article_id, &doc.article_id); 108 | a_doc.add_text(created_time, &doc.created_time); 109 | a_doc.add_text(title, &doc.title); 110 | a_doc.add_text(content, &doc.content); 111 | 112 | self.writer.add_document(a_doc); 113 | 114 | self.writer.commit()?; 115 | 116 | info!("add to tantivy index {:?}", doc.article_id); 117 | 118 | Ok(()) 119 | 120 | } 121 | 122 | pub fn update_doc(&mut self, doc: Doc2Index) -> tantivy::Result<()> { 123 | let schema = &self.schema; 124 | let article_id = schema.get_field("article_id").unwrap(); 125 | let _n = self.writer.delete_term(Term::from_field_text(article_id, &doc.article_id)); 126 | 127 | self.writer.commit()?; 128 | 129 | self.add_doc(doc) 130 | } 131 | 132 | pub fn delete_doc(&mut self, doc_id: &str) -> tantivy::Result<()> { 133 | let schema = &self.schema; 134 | let article_id = schema.get_field("article_id").unwrap(); 135 | let _n = self.writer.delete_term(Term::from_field_text(article_id, doc_id)); 136 | 137 | self.writer.commit()?; 138 | 139 | Ok(()) 140 | } 141 | 142 | pub fn query(&self, s: &str) -> tantivy::Result> { 143 | let schema = &self.schema; 144 | 145 | // self.index.load_searchers()?; 146 | // let searcher = self.index.searcher(); 147 | let searcher = self.reader.searcher(); 148 | 149 | let q = self.query_parser.parse_query(s)?; 150 | 151 | let mut top_docs = TopDocs::with_limit(50); 152 | 153 | let doc_addresses = searcher.search(&q, &mut top_docs)?; 154 | 155 | let mut r_vec: Vec = vec![]; 156 | for (_, doc_address) in doc_addresses { 157 | let retrieved_doc = searcher.doc(doc_address)?; 158 | let json_str = schema.to_json(&retrieved_doc); 159 | let doc_from_index: DocFromIndex = serde_json::from_str(&json_str).unwrap(); 160 | 161 | info!("{:?}", doc_from_index); 162 | let created_timestamp: i64 = doc_from_index.created_time[0].parse::().unwrap(); 163 | 164 | let new_doc = DocFromIndexOuter { 165 | article_id: doc_from_index.article_id[0].parse::().unwrap(), 166 | created_time: DateTime::::from_utc(NaiveDateTime::from_timestamp(created_timestamp, 0), Utc), 167 | title: doc_from_index.title[0].to_owned() 168 | }; 169 | 170 | r_vec.push(new_doc); 171 | } 172 | 173 | r_vec.sort_by(|a, b| b.created_time.cmp(&a.created_time)); 174 | 175 | Ok(r_vec) 176 | } 177 | } 178 | 179 | 180 | 181 | fn tokenizer() -> CangJieTokenizer { 182 | CangJieTokenizer { 183 | worker: Arc::new(Jieba::empty()), // empty dictionary 184 | option: TokenizerOption::Unicode, 185 | } 186 | } 187 | 188 | 189 | pub fn run_tantivy(tan_index_rx: Receiver<(TanAction, String, Option)>, tan_query_tx: Sender>) { 190 | 191 | let mut ttv_index = match init() { 192 | Ok(ttv_index) => { 193 | //Arc::new(Mutex::new(ttv_index)) 194 | ttv_index 195 | }, 196 | Err(e) => { 197 | panic!("{:?}", e); 198 | } 199 | }; 200 | 201 | thread::spawn(move || { 202 | loop { 203 | match tan_index_rx.recv() { 204 | Ok((action, head_data, doc)) => { 205 | match action { 206 | TanAction::Add => { 207 | if doc.is_some() { 208 | let _ = ttv_index.add_doc(doc.unwrap()); 209 | } 210 | }, 211 | TanAction::Update => { 212 | if doc.is_some() { 213 | let _ = ttv_index.update_doc(doc.unwrap()); 214 | } 215 | }, 216 | TanAction::Delete => { 217 | let _ = ttv_index.delete_doc(&head_data); 218 | }, 219 | TanAction::Query => { 220 | let docs = ttv_index.query(&head_data).unwrap_or(Vec::new()); 221 | let _ = tan_query_tx.send(docs); 222 | } 223 | } 224 | }, 225 | Err(_) => {} 226 | } 227 | } 228 | }); 229 | 230 | } 231 | -------------------------------------------------------------------------------- /static/css/base.css: -------------------------------------------------------------------------------- 1 | body { 2 | color: #222; 3 | max-width: 900px; 4 | margin: auto; 5 | padding: 0; 6 | } 7 | 8 | h1 { 9 | font-size: 30px; 10 | } 11 | 12 | h2 { 13 | font-size: 26px; 14 | } 15 | 16 | h3 { 17 | font-size: 20.5px; 18 | } 19 | 20 | h4 { 21 | font-size: 19.2px; 22 | } 23 | 24 | h5 { 25 | font-size: 18px; 26 | } 27 | 28 | h6 { 29 | font-size: 16px; 30 | } 31 | 32 | hr { 33 | border: 0; 34 | border-top: 1px solid #ccc; 35 | } 36 | 37 | table th { 38 | border-bottom: 1px solid #999; 39 | } 40 | 41 | 42 | /* p, ul { */ 43 | /* margin: 0; */ 44 | /* padding: 0; */ 45 | /* } */ 46 | 47 | ul li { 48 | line-height: 24px; 49 | list-style-type: none; 50 | text-overflow: ellipsis; 51 | overflow: hidden; 52 | white-space: nowrap; 53 | margin-top: 6px; 54 | } 55 | 56 | ol li { 57 | line-height: 24px; 58 | margin-top: 6px; 59 | } 60 | 61 | a { 62 | text-decoration: none; 63 | color: #222; 64 | } 65 | 66 | pre, code { 67 | background: #fbf1c7; 68 | padding: 0; 69 | font-family: "Source Code Pro","Fira Code",Menlo,Monaco,Consolas,"DejaVu Sans Mono",Inconsolata,"Courier New",monospace; 70 | } 71 | 72 | small { 73 | font-size: 13px; 74 | } 75 | 76 | blockquote { 77 | margin: 8px 0 8px 12px; 78 | padding: 0 8px; 79 | border-left: 2px solid #aaa; 80 | color: #666; 81 | } 82 | 83 | .right { 84 | float: right; 85 | } 86 | 87 | .left { 88 | float: left 89 | } 90 | 91 | .hide { 92 | display: none; 93 | } 94 | 95 | .header { 96 | height: 40px; 97 | line-height: 40px; 98 | border-bottom: gray 1px solid; 99 | padding: 0 10px; 100 | } 101 | 102 | .header .logo img { 103 | width: 40px; 104 | } 105 | 106 | .header .logo a { 107 | display: block; 108 | } 109 | 110 | 111 | 112 | .signpart { 113 | font-size: 14px; 114 | } 115 | 116 | .footer { 117 | border-top: gray 1px solid; 118 | line-height: 30px; 119 | font-size: 14px; 120 | text-align: center; 121 | } 122 | 123 | .body-content { 124 | padding: 10px; 125 | font-size: 14px; 126 | } 127 | 128 | .content-area { 129 | padding: 15px; 130 | } 131 | 132 | .strongit { 133 | font-size: 15px; 134 | } 135 | 136 | .icon { 137 | display: inline-block; 138 | } 139 | 140 | .delete { 141 | color: red; 142 | } 143 | 144 | .reply { 145 | color: blue; 146 | } 147 | 148 | .edit { 149 | color: green; 150 | } 151 | 152 | .return { 153 | font-size: 14px; 154 | color: #228; 155 | } 156 | 157 | .detail-body { 158 | font-size: 16px; 159 | padding: 20px 0px; 160 | } 161 | 162 | div.detail-body-wx { 163 | font-size: 15px; 164 | padding: 20px 0px; 165 | } 166 | 167 | .detail-body p, .comments p { 168 | line-height: 24px; 169 | /* padding: 7px 0; */ 170 | } 171 | 172 | 173 | .detail-body img { 174 | max-width: 100%; 175 | } 176 | 177 | /* 178 | .detail-body h1, 179 | .detail-body h2, 180 | .detail-body h3, 181 | .detail-body h4, 182 | .detail-body h5 { 183 | background: #efefef; 184 | padding: 10px; 185 | border-radius: 4px; 186 | } 187 | */ 188 | 189 | /* .detail-body ul { */ 190 | /* margin: 15px 0 15px 30px; */ 191 | /* } */ 192 | 193 | .detail-body ul li { 194 | list-style-type: disc; 195 | overflow: inherit; 196 | white-space: inherit; 197 | } 198 | 199 | .detail-body a:link, .comment-content a:link { 200 | color: blue; 201 | } 202 | 203 | .detail-body a:visited, .comment-content a:visited { 204 | color: purple; 205 | } 206 | 207 | .section-body ul li { 208 | line-height: 30px; 209 | } 210 | 211 | 212 | .vice-title { 213 | font-size: 14px; 214 | line-height: 20px; 215 | } 216 | 217 | .action_area { 218 | padding: 10px 0 10px 0; 219 | } 220 | 221 | .new-article, .new-comment { 222 | display: inline-block; 223 | margin-right: 10px; 224 | border: 1px solid #666; 225 | padding: 2px 4px; 226 | } 227 | 228 | .new-comment { 229 | margin-top: 20px; 230 | } 231 | 232 | .container { 233 | margin-top: 10px; 234 | margin-bottom: 24px; 235 | } 236 | 237 | .article-list { 238 | font-size: 16px; 239 | } 240 | 241 | .article-list ul { 242 | padding-left: 0; 243 | } 244 | 245 | .article-list li a.title:link { 246 | color: blue; 247 | } 248 | .article-list li a.title:visited { 249 | color: purple; 250 | } 251 | 252 | 253 | .article-list li .title { 254 | display: inline-block; 255 | text-overflow: ellipsis; 256 | overflow: hidden; 257 | } 258 | 259 | .article-list li .right { 260 | font-size: 14px; 261 | color: #666; 262 | } 263 | 264 | .head span { 265 | display: inline-block; 266 | border-bottom: 1px solid #666; 267 | font-size: 15px; 268 | line-height: 20px; 269 | color: #666; 270 | } 271 | 272 | .category-list-section { 273 | /* padding-top: 25px;*/ 274 | } 275 | 276 | .category-list-section ul li { 277 | float: left; 278 | padding-right: 8px; 279 | } 280 | 281 | .article-list li span .title { 282 | display: inline-block; 283 | } 284 | 285 | .article-list li .show-count { 286 | font-size: 14px; 287 | color: #666; 288 | } 289 | 290 | .article-list li .info { 291 | font-size: 14px; 292 | color: #666; 293 | } 294 | 295 | .detail-head { 296 | margin-bottom: 24px; 297 | } 298 | 299 | .body-content form { 300 | line-height: 40px; 301 | } 302 | 303 | /* .body-content form select { 304 | height: 20px; 305 | } */ 306 | 307 | .body-content form input[type=text] { 308 | min-width: 240px; 309 | height: 26px; 310 | font-size: 16px; 311 | width: 60%; 312 | padding-left: 4px; 313 | } 314 | 315 | .body-content form textarea { 316 | width: 90%; 317 | min-width: 280px; 318 | min-height: 400px; 319 | font-size: 15px; 320 | padding-left: 4px; 321 | } 322 | 323 | .article_detail_head { 324 | margin-top: 10px; 325 | } 326 | 327 | .article_detail_head .title { 328 | margin-top: 15px; 329 | } 330 | 331 | 332 | .comments { 333 | border-top: 2px solid #eee; 334 | } 335 | 336 | .comments .item { 337 | line-height: 24px; 338 | padding: 5px 0; 339 | } 340 | 341 | .comments .item .comment-title { 342 | font-size: 14px; 343 | padding: 4px 10px; 344 | border: 1px solid #eee; 345 | background-color: #f8f8f8; 346 | } 347 | 348 | .comments .item .comment-content { 349 | font-size: 16px; 350 | padding: 4px 10px; 351 | } 352 | 353 | .comments .item .comment-content pre { 354 | font-size: 14px; 355 | line-height: 16px; 356 | margin: 8px 0 0 0; 357 | padding: 8px; 358 | overflow: hidden; 359 | } 360 | 361 | .new-reply { 362 | line-height: 32px; 363 | padding-bottom: 10px; 364 | } 365 | 366 | .new-reply .article-title { 367 | font-weight: bold; 368 | } 369 | 370 | .current_page { 371 | text-decoration-line: underline; 372 | } 373 | 374 | .search_results .caption { 375 | line-height: 40px; 376 | font-size: 16px; 377 | } 378 | 379 | .search_results .item { 380 | line-height: 32px; 381 | font-size: 16px; 382 | padding-left: 20px; 383 | } 384 | 385 | .search_form .input { 386 | line-height: 40px; 387 | } 388 | 389 | .search_form .submit { 390 | height: 32px; 391 | } 392 | 393 | .search_results a:link { 394 | color: blue; 395 | } 396 | 397 | .search_results a:visited { 398 | color: purple; 399 | } 400 | 401 | .search_results .timestamp { 402 | font-size: 14px; 403 | } 404 | 405 | 406 | a.linked:link { 407 | color: blue; 408 | } 409 | 410 | a.linked:visited { 411 | color: purple; 412 | } 413 | 414 | iframe { 415 | width: 100%; 416 | height: 630px; 417 | border: 1px solid gray; 418 | } 419 | -------------------------------------------------------------------------------- /static/css/gruvbox-light.css: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Gruvbox style (light) (c) Pavel Pertsev (original style at https://github.com/morhetz/gruvbox) 4 | 5 | */ 6 | 7 | .hljs { 8 | display: block; 9 | overflow-x: auto; 10 | padding: 0.5em; 11 | background: #fbf1c7; 12 | } 13 | 14 | .hljs, 15 | .hljs-subst { 16 | color: #3c3836; 17 | } 18 | 19 | /* Gruvbox Red */ 20 | .hljs-deletion, 21 | .hljs-formula, 22 | .hljs-keyword, 23 | .hljs-link, 24 | .hljs-selector-tag { 25 | color: #9d0006; 26 | } 27 | 28 | /* Gruvbox Blue */ 29 | .hljs-built_in, 30 | .hljs-emphasis, 31 | .hljs-name, 32 | .hljs-quote, 33 | .hljs-strong, 34 | .hljs-title, 35 | .hljs-variable { 36 | color: #076678; 37 | } 38 | 39 | /* Gruvbox Yellow */ 40 | .hljs-attr, 41 | .hljs-params, 42 | .hljs-template-tag, 43 | .hljs-type { 44 | color: #b57614; 45 | } 46 | 47 | /* Gruvbox Purple */ 48 | .hljs-builtin-name, 49 | .hljs-doctag, 50 | .hljs-literal, 51 | .hljs-number { 52 | color: #8f3f71; 53 | } 54 | 55 | /* Gruvbox Orange */ 56 | .hljs-code, 57 | .hljs-meta, 58 | .hljs-regexp, 59 | .hljs-selector-id, 60 | .hljs-template-variable { 61 | color: #af3a03; 62 | } 63 | 64 | /* Gruvbox Green */ 65 | .hljs-addition, 66 | .hljs-meta-string, 67 | .hljs-section, 68 | .hljs-selector-attr, 69 | .hljs-selector-class, 70 | .hljs-string, 71 | .hljs-symbol { 72 | color: #79740e; 73 | } 74 | 75 | /* Gruvbox Aqua */ 76 | .hljs-attribute, 77 | .hljs-bullet, 78 | .hljs-class, 79 | .hljs-function, 80 | .hljs-function .hljs-keyword, 81 | .hljs-meta-keyword, 82 | .hljs-selector-pseudo, 83 | .hljs-tag { 84 | color: #427b58; 85 | } 86 | 87 | /* Gruvbox Gray */ 88 | .hljs-comment { 89 | color: #928374; 90 | } 91 | 92 | /* Gruvbox Purple */ 93 | .hljs-link_label, 94 | .hljs-literal, 95 | .hljs-number { 96 | color: #8f3f71; 97 | } 98 | 99 | .hljs-comment, 100 | .hljs-emphasis { 101 | font-style: italic; 102 | } 103 | 104 | .hljs-section, 105 | .hljs-strong, 106 | .hljs-tag { 107 | font-weight: bold; 108 | } 109 | 110 | .news-label { 111 | margin: .75rem 1.2rem 0 0; 112 | padding: .3rem .4rem; 113 | display: inline-block; 114 | font-size: .7rem; 115 | color: #333; 116 | border-radius: .2rem; 117 | border: 1px solid #000000; 118 | } 119 | -------------------------------------------------------------------------------- /static/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/miketang84/forustm/6739092ff14ed611391d0cbcff65de4296db6d93/static/favicon.ico -------------------------------------------------------------------------------- /static/img/qrcode_rust.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/miketang84/forustm/6739092ff14ed611391d0cbcff65de4296db6d93/static/img/qrcode_rust.png -------------------------------------------------------------------------------- /static/img/rust-logo.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /static/js/highlight.pack.js: -------------------------------------------------------------------------------- 1 | /*! highlight.js v9.12.0 | BSD3 License | git.io/hljslicense */ 2 | !function(e){var n="object"==typeof window&&window||"object"==typeof self&&self;"undefined"!=typeof exports?e(exports):n&&(n.hljs=e({}),"function"==typeof define&&define.amd&&define([],function(){return n.hljs}))}(function(e){function n(e){return e.replace(/&/g,"&").replace(//g,">")}function t(e){return e.nodeName.toLowerCase()}function r(e,n){var t=e&&e.exec(n);return t&&0===t.index}function a(e){return k.test(e)}function i(e){var n,t,r,i,o=e.className+" ";if(o+=e.parentNode?e.parentNode.className:"",t=B.exec(o))return w(t[1])?t[1]:"no-highlight";for(o=o.split(/\s+/),n=0,r=o.length;r>n;n++)if(i=o[n],a(i)||w(i))return i}function o(e){var n,t={},r=Array.prototype.slice.call(arguments,1);for(n in e)t[n]=e[n];return r.forEach(function(e){for(n in e)t[n]=e[n]}),t}function u(e){var n=[];return function r(e,a){for(var i=e.firstChild;i;i=i.nextSibling)3===i.nodeType?a+=i.nodeValue.length:1===i.nodeType&&(n.push({event:"start",offset:a,node:i}),a=r(i,a),t(i).match(/br|hr|img|input/)||n.push({event:"stop",offset:a,node:i}));return a}(e,0),n}function c(e,r,a){function i(){return e.length&&r.length?e[0].offset!==r[0].offset?e[0].offset"}function u(e){s+=""}function c(e){("start"===e.event?o:u)(e.node)}for(var l=0,s="",f=[];e.length||r.length;){var g=i();if(s+=n(a.substring(l,g[0].offset)),l=g[0].offset,g===e){f.reverse().forEach(u);do c(g.splice(0,1)[0]),g=i();while(g===e&&g.length&&g[0].offset===l);f.reverse().forEach(o)}else"start"===g[0].event?f.push(g[0].node):f.pop(),c(g.splice(0,1)[0])}return s+n(a.substr(l))}function l(e){return e.v&&!e.cached_variants&&(e.cached_variants=e.v.map(function(n){return o(e,{v:null},n)})),e.cached_variants||e.eW&&[o(e)]||[e]}function s(e){function n(e){return e&&e.source||e}function t(t,r){return new RegExp(n(t),"m"+(e.cI?"i":"")+(r?"g":""))}function r(a,i){if(!a.compiled){if(a.compiled=!0,a.k=a.k||a.bK,a.k){var o={},u=function(n,t){e.cI&&(t=t.toLowerCase()),t.split(" ").forEach(function(e){var t=e.split("|");o[t[0]]=[n,t[1]?Number(t[1]):1]})};"string"==typeof a.k?u("keyword",a.k):x(a.k).forEach(function(e){u(e,a.k[e])}),a.k=o}a.lR=t(a.l||/\w+/,!0),i&&(a.bK&&(a.b="\\b("+a.bK.split(" ").join("|")+")\\b"),a.b||(a.b=/\B|\b/),a.bR=t(a.b),a.e||a.eW||(a.e=/\B|\b/),a.e&&(a.eR=t(a.e)),a.tE=n(a.e)||"",a.eW&&i.tE&&(a.tE+=(a.e?"|":"")+i.tE)),a.i&&(a.iR=t(a.i)),null==a.r&&(a.r=1),a.c||(a.c=[]),a.c=Array.prototype.concat.apply([],a.c.map(function(e){return l("self"===e?a:e)})),a.c.forEach(function(e){r(e,a)}),a.starts&&r(a.starts,i);var c=a.c.map(function(e){return e.bK?"\\.?("+e.b+")\\.?":e.b}).concat([a.tE,a.i]).map(n).filter(Boolean);a.t=c.length?t(c.join("|"),!0):{exec:function(){return null}}}}r(e)}function f(e,t,a,i){function o(e,n){var t,a;for(t=0,a=n.c.length;a>t;t++)if(r(n.c[t].bR,e))return n.c[t]}function u(e,n){if(r(e.eR,n)){for(;e.endsParent&&e.parent;)e=e.parent;return e}return e.eW?u(e.parent,n):void 0}function c(e,n){return!a&&r(n.iR,e)}function l(e,n){var t=N.cI?n[0].toLowerCase():n[0];return e.k.hasOwnProperty(t)&&e.k[t]}function p(e,n,t,r){var a=r?"":I.classPrefix,i='',i+n+o}function h(){var e,t,r,a;if(!E.k)return n(k);for(a="",t=0,E.lR.lastIndex=0,r=E.lR.exec(k);r;)a+=n(k.substring(t,r.index)),e=l(E,r),e?(B+=e[1],a+=p(e[0],n(r[0]))):a+=n(r[0]),t=E.lR.lastIndex,r=E.lR.exec(k);return a+n(k.substr(t))}function d(){var e="string"==typeof E.sL;if(e&&!y[E.sL])return n(k);var t=e?f(E.sL,k,!0,x[E.sL]):g(k,E.sL.length?E.sL:void 0);return E.r>0&&(B+=t.r),e&&(x[E.sL]=t.top),p(t.language,t.value,!1,!0)}function b(){L+=null!=E.sL?d():h(),k=""}function v(e){L+=e.cN?p(e.cN,"",!0):"",E=Object.create(e,{parent:{value:E}})}function m(e,n){if(k+=e,null==n)return b(),0;var t=o(n,E);if(t)return t.skip?k+=n:(t.eB&&(k+=n),b(),t.rB||t.eB||(k=n)),v(t,n),t.rB?0:n.length;var r=u(E,n);if(r){var a=E;a.skip?k+=n:(a.rE||a.eE||(k+=n),b(),a.eE&&(k=n));do E.cN&&(L+=C),E.skip||(B+=E.r),E=E.parent;while(E!==r.parent);return r.starts&&v(r.starts,""),a.rE?0:n.length}if(c(n,E))throw new Error('Illegal lexeme "'+n+'" for mode "'+(E.cN||"")+'"');return k+=n,n.length||1}var N=w(e);if(!N)throw new Error('Unknown language: "'+e+'"');s(N);var R,E=i||N,x={},L="";for(R=E;R!==N;R=R.parent)R.cN&&(L=p(R.cN,"",!0)+L);var k="",B=0;try{for(var M,j,O=0;;){if(E.t.lastIndex=O,M=E.t.exec(t),!M)break;j=m(t.substring(O,M.index),M[0]),O=M.index+j}for(m(t.substr(O)),R=E;R.parent;R=R.parent)R.cN&&(L+=C);return{r:B,value:L,language:e,top:E}}catch(T){if(T.message&&-1!==T.message.indexOf("Illegal"))return{r:0,value:n(t)};throw T}}function g(e,t){t=t||I.languages||x(y);var r={r:0,value:n(e)},a=r;return t.filter(w).forEach(function(n){var t=f(n,e,!1);t.language=n,t.r>a.r&&(a=t),t.r>r.r&&(a=r,r=t)}),a.language&&(r.second_best=a),r}function p(e){return I.tabReplace||I.useBR?e.replace(M,function(e,n){return I.useBR&&"\n"===e?"
":I.tabReplace?n.replace(/\t/g,I.tabReplace):""}):e}function h(e,n,t){var r=n?L[n]:t,a=[e.trim()];return e.match(/\bhljs\b/)||a.push("hljs"),-1===e.indexOf(r)&&a.push(r),a.join(" ").trim()}function d(e){var n,t,r,o,l,s=i(e);a(s)||(I.useBR?(n=document.createElementNS("http://www.w3.org/1999/xhtml","div"),n.innerHTML=e.innerHTML.replace(/\n/g,"").replace(//g,"\n")):n=e,l=n.textContent,r=s?f(s,l,!0):g(l),t=u(n),t.length&&(o=document.createElementNS("http://www.w3.org/1999/xhtml","div"),o.innerHTML=r.value,r.value=c(t,u(o),l)),r.value=p(r.value),e.innerHTML=r.value,e.className=h(e.className,s,r.language),e.result={language:r.language,re:r.r},r.second_best&&(e.second_best={language:r.second_best.language,re:r.second_best.r}))}function b(e){I=o(I,e)}function v(){if(!v.called){v.called=!0;var e=document.querySelectorAll("pre code");E.forEach.call(e,d)}}function m(){addEventListener("DOMContentLoaded",v,!1),addEventListener("load",v,!1)}function N(n,t){var r=y[n]=t(e);r.aliases&&r.aliases.forEach(function(e){L[e]=n})}function R(){return x(y)}function w(e){return e=(e||"").toLowerCase(),y[e]||y[L[e]]}var E=[],x=Object.keys,y={},L={},k=/^(no-?highlight|plain|text)$/i,B=/\blang(?:uage)?-([\w-]+)\b/i,M=/((^(<[^>]+>|\t|)+|(?:\n)))/gm,C="
",I={classPrefix:"hljs-",tabReplace:null,useBR:!1,languages:void 0};return e.highlight=f,e.highlightAuto=g,e.fixMarkup=p,e.highlightBlock=d,e.configure=b,e.initHighlighting=v,e.initHighlightingOnLoad=m,e.registerLanguage=N,e.listLanguages=R,e.getLanguage=w,e.inherit=o,e.IR="[a-zA-Z]\\w*",e.UIR="[a-zA-Z_]\\w*",e.NR="\\b\\d+(\\.\\d+)?",e.CNR="(-?)(\\b0[xX][a-fA-F0-9]+|(\\b\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)",e.BNR="\\b(0b[01]+)",e.RSR="!|!=|!==|%|%=|&|&&|&=|\\*|\\*=|\\+|\\+=|,|-|-=|/=|/|:|;|<<|<<=|<=|<|===|==|=|>>>=|>>=|>=|>>>|>>|>|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~",e.BE={b:"\\\\[\\s\\S]",r:0},e.ASM={cN:"string",b:"'",e:"'",i:"\\n",c:[e.BE]},e.QSM={cN:"string",b:'"',e:'"',i:"\\n",c:[e.BE]},e.PWM={b:/\b(a|an|the|are|I'm|isn't|don't|doesn't|won't|but|just|should|pretty|simply|enough|gonna|going|wtf|so|such|will|you|your|they|like|more)\b/},e.C=function(n,t,r){var a=e.inherit({cN:"comment",b:n,e:t,c:[]},r||{});return a.c.push(e.PWM),a.c.push({cN:"doctag",b:"(?:TODO|FIXME|NOTE|BUG|XXX):",r:0}),a},e.CLCM=e.C("//","$"),e.CBCM=e.C("/\\*","\\*/"),e.HCM=e.C("#","$"),e.NM={cN:"number",b:e.NR,r:0},e.CNM={cN:"number",b:e.CNR,r:0},e.BNM={cN:"number",b:e.BNR,r:0},e.CSSNM={cN:"number",b:e.NR+"(%|em|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc|px|deg|grad|rad|turn|s|ms|Hz|kHz|dpi|dpcm|dppx)?",r:0},e.RM={cN:"regexp",b:/\//,e:/\/[gimuy]*/,i:/\n/,c:[e.BE,{b:/\[/,e:/\]/,r:0,c:[e.BE]}]},e.TM={cN:"title",b:e.IR,r:0},e.UTM={cN:"title",b:e.UIR,r:0},e.METHOD_GUARD={b:"\\.\\s*"+e.UIR,r:0},e});hljs.registerLanguage("apache",function(e){var r={cN:"number",b:"[\\$%]\\d+"};return{aliases:["apacheconf"],cI:!0,c:[e.HCM,{cN:"section",b:""},{cN:"attribute",b:/\w+/,r:0,k:{nomarkup:"order deny allow setenv rewriterule rewriteengine rewritecond documentroot sethandler errordocument loadmodule options header listen serverroot servername"},starts:{e:/$/,r:0,k:{literal:"on off all"},c:[{cN:"meta",b:"\\s\\[",e:"\\]$"},{cN:"variable",b:"[\\$%]\\{",e:"\\}",c:["self",r]},r,e.QSM]}}],i:/\S/}});hljs.registerLanguage("go",function(e){var t={keyword:"break default func interface select case map struct chan else goto package switch const fallthrough if range type continue for import return var go defer bool byte complex64 complex128 float32 float64 int8 int16 int32 int64 string uint8 uint16 uint32 uint64 int uint uintptr rune",literal:"true false iota nil",built_in:"append cap close complex copy imag len make new panic print println real recover delete"};return{aliases:["golang"],k:t,i:"%$#]",starts:{e:"$",sL:"bash"}}]}});hljs.registerLanguage("javascript",function(e){var r="[A-Za-z$_][0-9A-Za-z$_]*",t={keyword:"in of if for while finally var new function do return void else break catch instanceof with throw case default try this switch continue typeof delete let yield const export super debugger as async await static import from as",literal:"true false null undefined NaN Infinity",built_in:"eval isFinite isNaN parseFloat parseInt decodeURI decodeURIComponent encodeURI encodeURIComponent escape unescape Object Function Boolean Error EvalError InternalError RangeError ReferenceError StopIteration SyntaxError TypeError URIError Number Math Date String RegExp Array Float32Array Float64Array Int16Array Int32Array Int8Array Uint16Array Uint32Array Uint8Array Uint8ClampedArray ArrayBuffer DataView JSON Intl arguments require module console window document Symbol Set Map WeakSet WeakMap Proxy Reflect Promise"},a={cN:"number",v:[{b:"\\b(0[bB][01]+)"},{b:"\\b(0[oO][0-7]+)"},{b:e.CNR}],r:0},n={cN:"subst",b:"\\$\\{",e:"\\}",k:t,c:[]},c={cN:"string",b:"`",e:"`",c:[e.BE,n]};n.c=[e.ASM,e.QSM,c,a,e.RM];var s=n.c.concat([e.CBCM,e.CLCM]);return{aliases:["js","jsx"],k:t,c:[{cN:"meta",r:10,b:/^\s*['"]use (strict|asm)['"]/},{cN:"meta",b:/^#!/,e:/$/},e.ASM,e.QSM,c,e.CLCM,e.CBCM,a,{b:/[{,]\s*/,r:0,c:[{b:r+"\\s*:",rB:!0,r:0,c:[{cN:"attr",b:r,r:0}]}]},{b:"("+e.RSR+"|\\b(case|return|throw)\\b)\\s*",k:"return throw case",c:[e.CLCM,e.CBCM,e.RM,{cN:"function",b:"(\\(.*?\\)|"+r+")\\s*=>",rB:!0,e:"\\s*=>",c:[{cN:"params",v:[{b:r},{b:/\(\s*\)/},{b:/\(/,e:/\)/,eB:!0,eE:!0,k:t,c:s}]}]},{b://,sL:"xml",c:[{b:/<\w+\s*\/>/,skip:!0},{b:/<\w+/,e:/(\/\w+|\w+\/)>/,skip:!0,c:[{b:/<\w+\s*\/>/,skip:!0},"self"]}]}],r:0},{cN:"function",bK:"function",e:/\{/,eE:!0,c:[e.inherit(e.TM,{b:r}),{cN:"params",b:/\(/,e:/\)/,eB:!0,eE:!0,c:s}],i:/\[|%/},{b:/\$[(.]/},e.METHOD_GUARD,{cN:"class",bK:"class",e:/[{;=]/,eE:!0,i:/[:"\[\]]/,c:[{bK:"extends"},e.UTM]},{bK:"constructor",e:/\{/,eE:!0}],i:/#(?!!)/}});hljs.registerLanguage("ini",function(e){var b={cN:"string",c:[e.BE],v:[{b:"'''",e:"'''",r:10},{b:'"""',e:'"""',r:10},{b:'"',e:'"'},{b:"'",e:"'"}]};return{aliases:["toml"],cI:!0,i:/\S/,c:[e.C(";","$"),e.HCM,{cN:"section",b:/^\s*\[+/,e:/\]+/},{b:/^[a-z0-9\[\]_-]+\s*=\s*/,e:"$",rB:!0,c:[{cN:"attr",b:/[a-z0-9\[\]_-]+/},{b:/=/,eW:!0,r:0,c:[{cN:"literal",b:/\bon|off|true|false|yes|no\b/},{cN:"variable",v:[{b:/\$[\w\d"][\w\d_]*/},{b:/\$\{(.*?)}/}]},b,{cN:"number",b:/([\+\-]+)?[\d]+_[\d_]+/},e.NM]}]}]}});hljs.registerLanguage("coffeescript",function(e){var c={keyword:"in if for while finally new do return else break catch instanceof throw try this switch continue typeof delete debugger super yield import export from as default await then unless until loop of by when and or is isnt not",literal:"true false null undefined yes no on off",built_in:"npm require console print module global window document"},n="[A-Za-z$_][0-9A-Za-z$_]*",r={cN:"subst",b:/#\{/,e:/}/,k:c},i=[e.BNM,e.inherit(e.CNM,{starts:{e:"(\\s*/)?",r:0}}),{cN:"string",v:[{b:/'''/,e:/'''/,c:[e.BE]},{b:/'/,e:/'/,c:[e.BE]},{b:/"""/,e:/"""/,c:[e.BE,r]},{b:/"/,e:/"/,c:[e.BE,r]}]},{cN:"regexp",v:[{b:"///",e:"///",c:[r,e.HCM]},{b:"//[gim]*",r:0},{b:/\/(?![ *])(\\\/|.)*?\/[gim]*(?=\W|$)/}]},{b:"@"+n},{sL:"javascript",eB:!0,eE:!0,v:[{b:"```",e:"```"},{b:"`",e:"`"}]}];r.c=i;var s=e.inherit(e.TM,{b:n}),t="(\\(.*\\))?\\s*\\B[-=]>",o={cN:"params",b:"\\([^\\(]",rB:!0,c:[{b:/\(/,e:/\)/,k:c,c:["self"].concat(i)}]};return{aliases:["coffee","cson","iced"],k:c,i:/\/\*/,c:i.concat([e.C("###","###"),e.HCM,{cN:"function",b:"^\\s*"+n+"\\s*=\\s*"+t,e:"[-=]>",rB:!0,c:[s,o]},{b:/[:\(,=]\s*/,r:0,c:[{cN:"function",b:t,e:"[-=]>",rB:!0,c:[o]}]},{cN:"class",bK:"class",e:"$",i:/[:="\[\]]/,c:[{bK:"extends",eW:!0,i:/[:="\[\]]/,c:[s]},s]},{b:n+":",e:":",rB:!0,rE:!0,r:0}])}});hljs.registerLanguage("ruby",function(e){var b="[a-zA-Z_]\\w*[!?=]?|[-+~]\\@|<<|>>|=~|===?|<=>|[<>]=?|\\*\\*|[-/+%^&*~`|]|\\[\\]=?",r={keyword:"and then defined module in return redo if BEGIN retry end for self when next until do begin unless END rescue else break undef not super class case require yield alias while ensure elsif or include attr_reader attr_writer attr_accessor",literal:"true false nil"},c={cN:"doctag",b:"@[A-Za-z]+"},a={b:"#<",e:">"},s=[e.C("#","$",{c:[c]}),e.C("^\\=begin","^\\=end",{c:[c],r:10}),e.C("^__END__","\\n$")],n={cN:"subst",b:"#\\{",e:"}",k:r},t={cN:"string",c:[e.BE,n],v:[{b:/'/,e:/'/},{b:/"/,e:/"/},{b:/`/,e:/`/},{b:"%[qQwWx]?\\(",e:"\\)"},{b:"%[qQwWx]?\\[",e:"\\]"},{b:"%[qQwWx]?{",e:"}"},{b:"%[qQwWx]?<",e:">"},{b:"%[qQwWx]?/",e:"/"},{b:"%[qQwWx]?%",e:"%"},{b:"%[qQwWx]?-",e:"-"},{b:"%[qQwWx]?\\|",e:"\\|"},{b:/\B\?(\\\d{1,3}|\\x[A-Fa-f0-9]{1,2}|\\u[A-Fa-f0-9]{4}|\\?\S)\b/},{b:/<<(-?)\w+$/,e:/^\s*\w+$/}]},i={cN:"params",b:"\\(",e:"\\)",endsParent:!0,k:r},d=[t,a,{cN:"class",bK:"class module",e:"$|;",i:/=/,c:[e.inherit(e.TM,{b:"[A-Za-z_]\\w*(::\\w+)*(\\?|\\!)?"}),{b:"<\\s*",c:[{b:"("+e.IR+"::)?"+e.IR}]}].concat(s)},{cN:"function",bK:"def",e:"$|;",c:[e.inherit(e.TM,{b:b}),i].concat(s)},{b:e.IR+"::"},{cN:"symbol",b:e.UIR+"(\\!|\\?)?:",r:0},{cN:"symbol",b:":(?!\\s)",c:[t,{b:b}],r:0},{cN:"number",b:"(\\b0[0-7_]+)|(\\b0x[0-9a-fA-F_]+)|(\\b[1-9][0-9_]*(\\.[0-9_]+)?)|[0_]\\b",r:0},{b:"(\\$\\W)|((\\$|\\@\\@?)(\\w+))"},{cN:"params",b:/\|/,e:/\|/,k:r},{b:"("+e.RSR+"|unless)\\s*",k:"unless",c:[a,{cN:"regexp",c:[e.BE,n],i:/\n/,v:[{b:"/",e:"/[a-z]*"},{b:"%r{",e:"}[a-z]*"},{b:"%r\\(",e:"\\)[a-z]*"},{b:"%r!",e:"![a-z]*"},{b:"%r\\[",e:"\\][a-z]*"}]}].concat(s),r:0}].concat(s);n.c=d,i.c=d;var l="[>?]>",o="[\\w#]+\\(\\w+\\):\\d+:\\d+>",u="(\\w+-)?\\d+\\.\\d+\\.\\d(p\\d+)?[^>]+>",w=[{b:/^\s*=>/,starts:{e:"$",c:d}},{cN:"meta",b:"^("+l+"|"+o+"|"+u+")",starts:{e:"$",c:d}}];return{aliases:["rb","gemspec","podspec","thor","irb"],k:r,i:/\/\*/,c:s.concat(w).concat(d)}});hljs.registerLanguage("sql",function(e){var t=e.C("--","$");return{cI:!0,i:/[<>{}*#]/,c:[{bK:"begin end start commit rollback savepoint lock alter create drop rename call delete do handler insert load replace select truncate update set show pragma grant merge describe use explain help declare prepare execute deallocate release unlock purge reset change stop analyze cache flush optimize repair kill install uninstall checksum restore check backup revoke comment",e:/;/,eW:!0,l:/[\w\.]+/,k:{keyword:"abort abs absolute acc acce accep accept access accessed accessible account acos action activate add addtime admin administer advanced advise aes_decrypt aes_encrypt after agent aggregate ali alia alias allocate allow alter always analyze ancillary and any anydata anydataset anyschema anytype apply archive archived archivelog are as asc ascii asin assembly assertion associate asynchronous at atan atn2 attr attri attrib attribu attribut attribute attributes audit authenticated authentication authid authors auto autoallocate autodblink autoextend automatic availability avg backup badfile basicfile before begin beginning benchmark between bfile bfile_base big bigfile bin binary_double binary_float binlog bit_and bit_count bit_length bit_or bit_xor bitmap blob_base block blocksize body both bound buffer_cache buffer_pool build bulk by byte byteordermark bytes cache caching call calling cancel capacity cascade cascaded case cast catalog category ceil ceiling chain change changed char_base char_length character_length characters characterset charindex charset charsetform charsetid check checksum checksum_agg child choose chr chunk class cleanup clear client clob clob_base clone close cluster_id cluster_probability cluster_set clustering coalesce coercibility col collate collation collect colu colum column column_value columns columns_updated comment commit compact compatibility compiled complete composite_limit compound compress compute concat concat_ws concurrent confirm conn connec connect connect_by_iscycle connect_by_isleaf connect_by_root connect_time connection consider consistent constant constraint constraints constructor container content contents context contributors controlfile conv convert convert_tz corr corr_k corr_s corresponding corruption cos cost count count_big counted covar_pop covar_samp cpu_per_call cpu_per_session crc32 create creation critical cross cube cume_dist curdate current current_date current_time current_timestamp current_user cursor curtime customdatum cycle data database databases datafile datafiles datalength date_add date_cache date_format date_sub dateadd datediff datefromparts datename datepart datetime2fromparts day day_to_second dayname dayofmonth dayofweek dayofyear days db_role_change dbtimezone ddl deallocate declare decode decompose decrement decrypt deduplicate def defa defau defaul default defaults deferred defi defin define degrees delayed delegate delete delete_all delimited demand dense_rank depth dequeue des_decrypt des_encrypt des_key_file desc descr descri describ describe descriptor deterministic diagnostics difference dimension direct_load directory disable disable_all disallow disassociate discardfile disconnect diskgroup distinct distinctrow distribute distributed div do document domain dotnet double downgrade drop dumpfile duplicate duration each edition editionable editions element ellipsis else elsif elt empty enable enable_all enclosed encode encoding encrypt end end-exec endian enforced engine engines enqueue enterprise entityescaping eomonth error errors escaped evalname evaluate event eventdata events except exception exceptions exchange exclude excluding execu execut execute exempt exists exit exp expire explain export export_set extended extent external external_1 external_2 externally extract failed failed_login_attempts failover failure far fast feature_set feature_value fetch field fields file file_name_convert filesystem_like_logging final finish first first_value fixed flash_cache flashback floor flush following follows for forall force form forma format found found_rows freelist freelists freepools fresh from from_base64 from_days ftp full function general generated get get_format get_lock getdate getutcdate global global_name globally go goto grant grants greatest group group_concat group_id grouping grouping_id groups gtid_subtract guarantee guard handler hash hashkeys having hea head headi headin heading heap help hex hierarchy high high_priority hosts hour http id ident_current ident_incr ident_seed identified identity idle_time if ifnull ignore iif ilike ilm immediate import in include including increment index indexes indexing indextype indicator indices inet6_aton inet6_ntoa inet_aton inet_ntoa infile initial initialized initially initrans inmemory inner innodb input insert install instance instantiable instr interface interleaved intersect into invalidate invisible is is_free_lock is_ipv4 is_ipv4_compat is_not is_not_null is_used_lock isdate isnull isolation iterate java join json json_exists keep keep_duplicates key keys kill language large last last_day last_insert_id last_value lax lcase lead leading least leaves left len lenght length less level levels library like like2 like4 likec limit lines link list listagg little ln load load_file lob lobs local localtime localtimestamp locate locator lock locked log log10 log2 logfile logfiles logging logical logical_reads_per_call logoff logon logs long loop low low_priority lower lpad lrtrim ltrim main make_set makedate maketime managed management manual map mapping mask master master_pos_wait match matched materialized max maxextents maximize maxinstances maxlen maxlogfiles maxloghistory maxlogmembers maxsize maxtrans md5 measures median medium member memcompress memory merge microsecond mid migration min minextents minimum mining minus minute minvalue missing mod mode model modification modify module monitoring month months mount move movement multiset mutex name name_const names nan national native natural nav nchar nclob nested never new newline next nextval no no_write_to_binlog noarchivelog noaudit nobadfile nocheck nocompress nocopy nocycle nodelay nodiscardfile noentityescaping noguarantee nokeep nologfile nomapping nomaxvalue nominimize nominvalue nomonitoring none noneditionable nonschema noorder nopr nopro noprom nopromp noprompt norely noresetlogs noreverse normal norowdependencies noschemacheck noswitch not nothing notice notrim novalidate now nowait nth_value nullif nulls num numb numbe nvarchar nvarchar2 object ocicoll ocidate ocidatetime ociduration ociinterval ociloblocator ocinumber ociref ocirefcursor ocirowid ocistring ocitype oct octet_length of off offline offset oid oidindex old on online only opaque open operations operator optimal optimize option optionally or oracle oracle_date oradata ord ordaudio orddicom orddoc order ordimage ordinality ordvideo organization orlany orlvary out outer outfile outline output over overflow overriding package pad parallel parallel_enable parameters parent parse partial partition partitions pascal passing password password_grace_time password_lock_time password_reuse_max password_reuse_time password_verify_function patch path patindex pctincrease pctthreshold pctused pctversion percent percent_rank percentile_cont percentile_disc performance period period_add period_diff permanent physical pi pipe pipelined pivot pluggable plugin policy position post_transaction pow power pragma prebuilt precedes preceding precision prediction prediction_cost prediction_details prediction_probability prediction_set prepare present preserve prior priority private private_sga privileges procedural procedure procedure_analyze processlist profiles project prompt protection public publishingservername purge quarter query quick quiesce quota quotename radians raise rand range rank raw read reads readsize rebuild record records recover recovery recursive recycle redo reduced ref reference referenced references referencing refresh regexp_like register regr_avgx regr_avgy regr_count regr_intercept regr_r2 regr_slope regr_sxx regr_sxy reject rekey relational relative relaylog release release_lock relies_on relocate rely rem remainder rename repair repeat replace replicate replication required reset resetlogs resize resource respect restore restricted result result_cache resumable resume retention return returning returns reuse reverse revoke right rlike role roles rollback rolling rollup round row row_count rowdependencies rowid rownum rows rtrim rules safe salt sample save savepoint sb1 sb2 sb4 scan schema schemacheck scn scope scroll sdo_georaster sdo_topo_geometry search sec_to_time second section securefile security seed segment select self sequence sequential serializable server servererror session session_user sessions_per_user set sets settings sha sha1 sha2 share shared shared_pool short show shrink shutdown si_averagecolor si_colorhistogram si_featurelist si_positionalcolor si_stillimage si_texture siblings sid sign sin size size_t sizes skip slave sleep smalldatetimefromparts smallfile snapshot some soname sort soundex source space sparse spfile split sql sql_big_result sql_buffer_result sql_cache sql_calc_found_rows sql_small_result sql_variant_property sqlcode sqldata sqlerror sqlname sqlstate sqrt square standalone standby start starting startup statement static statistics stats_binomial_test stats_crosstab stats_ks_test stats_mode stats_mw_test stats_one_way_anova stats_t_test_ stats_t_test_indep stats_t_test_one stats_t_test_paired stats_wsr_test status std stddev stddev_pop stddev_samp stdev stop storage store stored str str_to_date straight_join strcmp strict string struct stuff style subdate subpartition subpartitions substitutable substr substring subtime subtring_index subtype success sum suspend switch switchoffset switchover sync synchronous synonym sys sys_xmlagg sysasm sysaux sysdate sysdatetimeoffset sysdba sysoper system system_user sysutcdatetime table tables tablespace tan tdo template temporary terminated tertiary_weights test than then thread through tier ties time time_format time_zone timediff timefromparts timeout timestamp timestampadd timestampdiff timezone_abbr timezone_minute timezone_region to to_base64 to_date to_days to_seconds todatetimeoffset trace tracking transaction transactional translate translation treat trigger trigger_nestlevel triggers trim truncate try_cast try_convert try_parse type ub1 ub2 ub4 ucase unarchived unbounded uncompress under undo unhex unicode uniform uninstall union unique unix_timestamp unknown unlimited unlock unpivot unrecoverable unsafe unsigned until untrusted unusable unused update updated upgrade upped upper upsert url urowid usable usage use use_stored_outlines user user_data user_resources users using utc_date utc_timestamp uuid uuid_short validate validate_password_strength validation valist value values var var_samp varcharc vari varia variab variabl variable variables variance varp varraw varrawc varray verify version versions view virtual visible void wait wallet warning warnings week weekday weekofyear wellformed when whene whenev wheneve whenever where while whitespace with within without work wrapped xdb xml xmlagg xmlattributes xmlcast xmlcolattval xmlelement xmlexists xmlforest xmlindex xmlnamespaces xmlpi xmlquery xmlroot xmlschema xmlserialize xmltable xmltype xor year year_to_month years yearweek",literal:"true false null",built_in:"array bigint binary bit blob boolean char character date dec decimal float int int8 integer interval number numeric real record serial serial8 smallint text varchar varying void"},c:[{cN:"string",b:"'",e:"'",c:[e.BE,{b:"''"}]},{cN:"string",b:'"',e:'"',c:[e.BE,{b:'""'}]},{cN:"string",b:"`",e:"`",c:[e.BE]},e.CNM,e.CBCM,t]},e.CBCM,t]}});hljs.registerLanguage("java",function(e){var a="[À-ʸa-zA-Z_$][À-ʸa-zA-Z_$0-9]*",t=a+"(<"+a+"(\\s*,\\s*"+a+")*>)?",r="false synchronized int abstract float private char boolean static null if const for true while long strictfp finally protected import native final void enum else break transient catch instanceof byte super volatile case assert short package default double public try this switch continue throws protected public private module requires exports do",s="\\b(0[bB]([01]+[01_]+[01]+|[01]+)|0[xX]([a-fA-F0-9]+[a-fA-F0-9_]+[a-fA-F0-9]+|[a-fA-F0-9]+)|(([\\d]+[\\d_]+[\\d]+|[\\d]+)(\\.([\\d]+[\\d_]+[\\d]+|[\\d]+))?|\\.([\\d]+[\\d_]+[\\d]+|[\\d]+))([eE][-+]?\\d+)?)[lLfF]?",c={cN:"number",b:s,r:0};return{aliases:["jsp"],k:r,i:/<\/|#/,c:[e.C("/\\*\\*","\\*/",{r:0,c:[{b:/\w+@/,r:0},{cN:"doctag",b:"@[A-Za-z]+"}]}),e.CLCM,e.CBCM,e.ASM,e.QSM,{cN:"class",bK:"class interface",e:/[{;=]/,eE:!0,k:"class interface",i:/[:"\[\]]/,c:[{bK:"extends implements"},e.UTM]},{bK:"new throw return else",r:0},{cN:"function",b:"("+t+"\\s+)+"+e.UIR+"\\s*\\(",rB:!0,e:/[{;=]/,eE:!0,k:r,c:[{b:e.UIR+"\\s*\\(",rB:!0,r:0,c:[e.UTM]},{cN:"params",b:/\(/,e:/\)/,k:r,r:0,c:[e.ASM,e.QSM,e.CNM,e.CBCM]},e.CLCM,e.CBCM]},c,{cN:"meta",b:"@[A-Za-z]+"}]}});hljs.registerLanguage("http",function(e){var t="HTTP/[0-9\\.]+";return{aliases:["https"],i:"\\S",c:[{b:"^"+t,e:"$",c:[{cN:"number",b:"\\b\\d{3}\\b"}]},{b:"^[A-Z]+ (.*?) "+t+"$",rB:!0,e:"$",c:[{cN:"string",b:" ",e:" ",eB:!0,eE:!0},{b:t},{cN:"keyword",b:"[A-Z]+"}]},{cN:"attribute",b:"^\\w",e:": ",eE:!0,i:"\\n|\\s|=",starts:{e:"$",r:0}},{b:"\\n\\n",starts:{sL:[],eW:!0}}]}});hljs.registerLanguage("perl",function(e){var t="getpwent getservent quotemeta msgrcv scalar kill dbmclose undef lc ma syswrite tr send umask sysopen shmwrite vec qx utime local oct semctl localtime readpipe do return format read sprintf dbmopen pop getpgrp not getpwnam rewinddir qqfileno qw endprotoent wait sethostent bless s|0 opendir continue each sleep endgrent shutdown dump chomp connect getsockname die socketpair close flock exists index shmgetsub for endpwent redo lstat msgctl setpgrp abs exit select print ref gethostbyaddr unshift fcntl syscall goto getnetbyaddr join gmtime symlink semget splice x|0 getpeername recv log setsockopt cos last reverse gethostbyname getgrnam study formline endhostent times chop length gethostent getnetent pack getprotoent getservbyname rand mkdir pos chmod y|0 substr endnetent printf next open msgsnd readdir use unlink getsockopt getpriority rindex wantarray hex system getservbyport endservent int chr untie rmdir prototype tell listen fork shmread ucfirst setprotoent else sysseek link getgrgid shmctl waitpid unpack getnetbyname reset chdir grep split require caller lcfirst until warn while values shift telldir getpwuid my getprotobynumber delete and sort uc defined srand accept package seekdir getprotobyname semop our rename seek if q|0 chroot sysread setpwent no crypt getc chown sqrt write setnetent setpriority foreach tie sin msgget map stat getlogin unless elsif truncate exec keys glob tied closedirioctl socket readlink eval xor readline binmode setservent eof ord bind alarm pipe atan2 getgrent exp time push setgrent gt lt or ne m|0 break given say state when",r={cN:"subst",b:"[$@]\\{",e:"\\}",k:t},s={b:"->{",e:"}"},n={v:[{b:/\$\d/},{b:/[\$%@](\^\w\b|#\w+(::\w+)*|{\w+}|\w+(::\w*)*)/},{b:/[\$%@][^\s\w{]/,r:0}]},i=[e.BE,r,n],o=[n,e.HCM,e.C("^\\=\\w","\\=cut",{eW:!0}),s,{cN:"string",c:i,v:[{b:"q[qwxr]?\\s*\\(",e:"\\)",r:5},{b:"q[qwxr]?\\s*\\[",e:"\\]",r:5},{b:"q[qwxr]?\\s*\\{",e:"\\}",r:5},{b:"q[qwxr]?\\s*\\|",e:"\\|",r:5},{b:"q[qwxr]?\\s*\\<",e:"\\>",r:5},{b:"qw\\s+q",e:"q",r:5},{b:"'",e:"'",c:[e.BE]},{b:'"',e:'"'},{b:"`",e:"`",c:[e.BE]},{b:"{\\w+}",c:[],r:0},{b:"-?\\w+\\s*\\=\\>",c:[],r:0}]},{cN:"number",b:"(\\b0[0-7_]+)|(\\b0x[0-9a-fA-F_]+)|(\\b[1-9][0-9_]*(\\.[0-9_]+)?)|[0_]\\b",r:0},{b:"(\\/\\/|"+e.RSR+"|\\b(split|return|print|reverse|grep)\\b)\\s*",k:"split return print reverse grep",r:0,c:[e.HCM,{cN:"regexp",b:"(s|tr|y)/(\\\\.|[^/])*/(\\\\.|[^/])*/[a-z]*",r:10},{cN:"regexp",b:"(m|qr)?/",e:"/[a-z]*",c:[e.BE],r:0}]},{cN:"function",bK:"sub",e:"(\\s*\\(.*?\\))?[;{]",eE:!0,r:5,c:[e.TM]},{b:"-\\w\\b",r:0},{b:"^__DATA__$",e:"^__END__$",sL:"mojolicious",c:[{b:"^@@.*",e:"$",cN:"comment"}]}];return r.c=o,s.c=o,{aliases:["pl","pm"],l:/[\w\.]+/,k:t,c:o}});hljs.registerLanguage("xml",function(s){var e="[A-Za-z0-9\\._:-]+",t={eW:!0,i:/`]+/}]}]}]};return{aliases:["html","xhtml","rss","atom","xjb","xsd","xsl","plist"],cI:!0,c:[{cN:"meta",b:"",r:10,c:[{b:"\\[",e:"\\]"}]},s.C("",{r:10}),{b:"<\\!\\[CDATA\\[",e:"\\]\\]>",r:10},{b:/<\?(php)?/,e:/\?>/,sL:"php",c:[{b:"/\\*",e:"\\*/",skip:!0}]},{cN:"tag",b:"|$)",e:">",k:{name:"style"},c:[t],starts:{e:"",rE:!0,sL:["css","xml"]}},{cN:"tag",b:"|$)",e:">",k:{name:"script"},c:[t],starts:{e:"",rE:!0,sL:["actionscript","javascript","handlebars","xml"]}},{cN:"meta",v:[{b:/<\?xml/,e:/\?>/,r:10},{b:/<\?\w+/,e:/\?>/}]},{cN:"tag",b:"",c:[{cN:"name",b:/[^\/><\s]+/,r:0},t]}]}});hljs.registerLanguage("diff",function(e){return{aliases:["patch"],c:[{cN:"meta",r:10,v:[{b:/^@@ +\-\d+,\d+ +\+\d+,\d+ +@@$/},{b:/^\*\*\* +\d+,\d+ +\*\*\*\*$/},{b:/^\-\-\- +\d+,\d+ +\-\-\-\-$/}]},{cN:"comment",v:[{b:/Index: /,e:/$/},{b:/={3,}/,e:/$/},{b:/^\-{3}/,e:/$/},{b:/^\*{3} /,e:/$/},{b:/^\+{3}/,e:/$/},{b:/\*{5}/,e:/\*{5}$/}]},{cN:"addition",b:"^\\+",e:"$"},{cN:"deletion",b:"^\\-",e:"$"},{cN:"addition",b:"^\\!",e:"$"}]}});hljs.registerLanguage("cpp",function(t){var e={cN:"keyword",b:"\\b[a-z\\d_]*_t\\b"},r={cN:"string",v:[{b:'(u8?|U)?L?"',e:'"',i:"\\n",c:[t.BE]},{b:'(u8?|U)?R"',e:'"',c:[t.BE]},{b:"'\\\\?.",e:"'",i:"."}]},s={cN:"number",v:[{b:"\\b(0b[01']+)"},{b:"(-?)\\b([\\d']+(\\.[\\d']*)?|\\.[\\d']+)(u|U|l|L|ul|UL|f|F|b|B)"},{b:"(-?)(\\b0[xX][a-fA-F0-9']+|(\\b[\\d']+(\\.[\\d']*)?|\\.[\\d']+)([eE][-+]?[\\d']+)?)"}],r:0},i={cN:"meta",b:/#\s*[a-z]+\b/,e:/$/,k:{"meta-keyword":"if else elif endif define undef warning error line pragma ifdef ifndef include"},c:[{b:/\\\n/,r:0},t.inherit(r,{cN:"meta-string"}),{cN:"meta-string",b:/<[^\n>]*>/,e:/$/,i:"\\n"},t.CLCM,t.CBCM]},a=t.IR+"\\s*\\(",c={keyword:"int float while private char catch import module export virtual operator sizeof dynamic_cast|10 typedef const_cast|10 const for static_cast|10 union namespace unsigned long volatile static protected bool template mutable if public friend do goto auto void enum else break extern using asm case typeid short reinterpret_cast|10 default double register explicit signed typename try this switch continue inline delete alignof constexpr decltype noexcept static_assert thread_local restrict _Bool complex _Complex _Imaginary atomic_bool atomic_char atomic_schar atomic_uchar atomic_short atomic_ushort atomic_int atomic_uint atomic_long atomic_ulong atomic_llong atomic_ullong new throw return and or not",built_in:"std string cin cout cerr clog stdin stdout stderr stringstream istringstream ostringstream auto_ptr deque list queue stack vector map set bitset multiset multimap unordered_set unordered_map unordered_multiset unordered_multimap array shared_ptr abort abs acos asin atan2 atan calloc ceil cosh cos exit exp fabs floor fmod fprintf fputs free frexp fscanf isalnum isalpha iscntrl isdigit isgraph islower isprint ispunct isspace isupper isxdigit tolower toupper labs ldexp log10 log malloc realloc memchr memcmp memcpy memset modf pow printf putchar puts scanf sinh sin snprintf sprintf sqrt sscanf strcat strchr strcmp strcpy strcspn strlen strncat strncmp strncpy strpbrk strrchr strspn strstr tanh tan vfprintf vprintf vsprintf endl initializer_list unique_ptr",literal:"true false nullptr NULL"},n=[e,t.CLCM,t.CBCM,s,r];return{aliases:["c","cc","h","c++","h++","hpp"],k:c,i:"",k:c,c:["self",e]},{b:t.IR+"::",k:c},{v:[{b:/=/,e:/;/},{b:/\(/,e:/\)/},{bK:"new throw return else",e:/;/}],k:c,c:n.concat([{b:/\(/,e:/\)/,k:c,c:n.concat(["self"]),r:0}]),r:0},{cN:"function",b:"("+t.IR+"[\\*&\\s]+)+"+a,rB:!0,e:/[{;=]/,eE:!0,k:c,i:/[^\w\s\*&]/,c:[{b:a,rB:!0,c:[t.TM],r:0},{cN:"params",b:/\(/,e:/\)/,k:c,r:0,c:[t.CLCM,t.CBCM,r,s,e]},t.CLCM,t.CBCM,i]},{cN:"class",bK:"class struct",e:/[{;:]/,c:[{b://,c:["self"]},t.TM]}]),exports:{preprocessor:i,strings:r,k:c}}});hljs.registerLanguage("json",function(e){var i={literal:"true false null"},n=[e.QSM,e.CNM],r={e:",",eW:!0,eE:!0,c:n,k:i},t={b:"{",e:"}",c:[{cN:"attr",b:/"/,e:/"/,c:[e.BE],i:"\\n"},e.inherit(r,{b:/:/})],i:"\\S"},c={b:"\\[",e:"\\]",c:[e.inherit(r)],i:"\\S"};return n.splice(n.length,0,t,c),{c:n,k:i,i:"\\S"}});hljs.registerLanguage("cs",function(e){var i={keyword:"abstract as base bool break byte case catch char checked const continue decimal default delegate do double enum event explicit extern finally fixed float for foreach goto if implicit in int interface internal is lock long nameof object operator out override params private protected public readonly ref sbyte sealed short sizeof stackalloc static string struct switch this try typeof uint ulong unchecked unsafe ushort using virtual void volatile while add alias ascending async await by descending dynamic equals from get global group into join let on orderby partial remove select set value var where yield",literal:"null false true"},t={cN:"string",b:'@"',e:'"',c:[{b:'""'}]},r=e.inherit(t,{i:/\n/}),a={cN:"subst",b:"{",e:"}",k:i},c=e.inherit(a,{i:/\n/}),n={cN:"string",b:/\$"/,e:'"',i:/\n/,c:[{b:"{{"},{b:"}}"},e.BE,c]},s={cN:"string",b:/\$@"/,e:'"',c:[{b:"{{"},{b:"}}"},{b:'""'},a]},o=e.inherit(s,{i:/\n/,c:[{b:"{{"},{b:"}}"},{b:'""'},c]});a.c=[s,n,t,e.ASM,e.QSM,e.CNM,e.CBCM],c.c=[o,n,r,e.ASM,e.QSM,e.CNM,e.inherit(e.CBCM,{i:/\n/})];var l={v:[s,n,t,e.ASM,e.QSM]},b=e.IR+"(<"+e.IR+"(\\s*,\\s*"+e.IR+")*>)?(\\[\\])?";return{aliases:["csharp"],k:i,i:/::/,c:[e.C("///","$",{rB:!0,c:[{cN:"doctag",v:[{b:"///",r:0},{b:""},{b:""}]}]}),e.CLCM,e.CBCM,{cN:"meta",b:"#",e:"$",k:{"meta-keyword":"if else elif endif define undef warning error line region endregion pragma checksum"}},l,e.CNM,{bK:"class interface",e:/[{;=]/,i:/[^\s:]/,c:[e.TM,e.CLCM,e.CBCM]},{bK:"namespace",e:/[{;=]/,i:/[^\s:]/,c:[e.inherit(e.TM,{b:"[a-zA-Z](\\.?\\w)*"}),e.CLCM,e.CBCM]},{cN:"meta",b:"^\\s*\\[",eB:!0,e:"\\]",eE:!0,c:[{cN:"meta-string",b:/"/,e:/"/}]},{bK:"new return throw await else",r:0},{cN:"function",b:"("+b+"\\s+)+"+e.IR+"\\s*\\(",rB:!0,e:/[{;=]/,eE:!0,k:i,c:[{b:e.IR+"\\s*\\(",rB:!0,c:[e.TM],r:0},{cN:"params",b:/\(/,e:/\)/,eB:!0,eE:!0,k:i,r:0,c:[l,e.CNM,e.CBCM]},e.CLCM,e.CBCM]}]}});hljs.registerLanguage("nginx",function(e){var r={cN:"variable",v:[{b:/\$\d+/},{b:/\$\{/,e:/}/},{b:"[\\$\\@]"+e.UIR}]},b={eW:!0,l:"[a-z/_]+",k:{literal:"on off yes no true false none blocked debug info notice warn error crit select break last permanent redirect kqueue rtsig epoll poll /dev/poll"},r:0,i:"=>",c:[e.HCM,{cN:"string",c:[e.BE,r],v:[{b:/"/,e:/"/},{b:/'/,e:/'/}]},{b:"([a-z]+):/",e:"\\s",eW:!0,eE:!0,c:[r]},{cN:"regexp",c:[e.BE,r],v:[{b:"\\s\\^",e:"\\s|{|;",rE:!0},{b:"~\\*?\\s+",e:"\\s|{|;",rE:!0},{b:"\\*(\\.[a-z\\-]+)+"},{b:"([a-z\\-]+\\.)+\\*"}]},{cN:"number",b:"\\b\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}(:\\d{1,5})?\\b"},{cN:"number",b:"\\b\\d+[kKmMgGdshdwy]*\\b",r:0},r]};return{aliases:["nginxconf"],c:[e.HCM,{b:e.UIR+"\\s+{",rB:!0,e:"{",c:[{cN:"section",b:e.UIR}],r:0},{b:e.UIR+"\\s",e:";|{",rB:!0,c:[{cN:"attribute",b:e.UIR,starts:b}],r:0}],i:"[^\\s\\}]"}});hljs.registerLanguage("rust",function(e){var t="([ui](8|16|32|64|128|size)|f(32|64))?",r="alignof as be box break const continue crate do else enum extern false fn for if impl in let loop match mod mut offsetof once priv proc pub pure ref return self Self sizeof static struct super trait true type typeof unsafe unsized use virtual while where yield move default",n="drop i8 i16 i32 i64 i128 isize u8 u16 u32 u64 u128 usize f32 f64 str char bool Box Option Result String Vec Copy Send Sized Sync Drop Fn FnMut FnOnce ToOwned Clone Debug PartialEq PartialOrd Eq Ord AsRef AsMut Into From Default Iterator Extend IntoIterator DoubleEndedIterator ExactSizeIterator SliceConcatExt ToString assert! assert_eq! bitflags! bytes! cfg! col! concat! concat_idents! debug_assert! debug_assert_eq! env! panic! file! format! format_args! include_bin! include_str! line! local_data_key! module_path! option_env! print! println! select! stringify! try! unimplemented! unreachable! vec! write! writeln! macro_rules! assert_ne! debug_assert_ne!";return{aliases:["rs"],k:{keyword:r,literal:"true false Some None Ok Err",built_in:n},l:e.IR+"!?",i:""}]}});hljs.registerLanguage("markdown",function(e){return{aliases:["md","mkdown","mkd"],c:[{cN:"section",v:[{b:"^#{1,6}",e:"$"},{b:"^.+?\\n[=-]{2,}$"}]},{b:"<",e:">",sL:"xml",r:0},{cN:"bullet",b:"^([*+-]|(\\d+\\.))\\s+"},{cN:"strong",b:"[*_]{2}.+?[*_]{2}"},{cN:"emphasis",v:[{b:"\\*.+?\\*"},{b:"_.+?_",r:0}]},{cN:"quote",b:"^>\\s+",e:"$"},{cN:"code",v:[{b:"^```w*s*$",e:"^```s*$"},{b:"`.+?`"},{b:"^( {4}| )",e:"$",r:0}]},{b:"^[-\\*]{3,}",e:"$"},{b:"\\[.+?\\][\\(\\[].*?[\\)\\]]",rB:!0,c:[{cN:"string",b:"\\[",e:"\\]",eB:!0,rE:!0,r:0},{cN:"link",b:"\\]\\(",e:"\\)",eB:!0,eE:!0},{cN:"symbol",b:"\\]\\[",e:"\\]",eB:!0,eE:!0}],r:10},{b:/^\[[^\n]+\]:/,rB:!0,c:[{cN:"symbol",b:/\[/,e:/\]/,eB:!0,eE:!0},{cN:"link",b:/:\s*/,e:/$/,eB:!0}]}]}});hljs.registerLanguage("css",function(e){var c="[a-zA-Z-][a-zA-Z0-9_-]*",t={b:/[A-Z\_\.\-]+\s*:/,rB:!0,e:";",eW:!0,c:[{cN:"attribute",b:/\S/,e:":",eE:!0,starts:{eW:!0,eE:!0,c:[{b:/[\w-]+\(/,rB:!0,c:[{cN:"built_in",b:/[\w-]+/},{b:/\(/,e:/\)/,c:[e.ASM,e.QSM]}]},e.CSSNM,e.QSM,e.ASM,e.CBCM,{cN:"number",b:"#[0-9A-Fa-f]+"},{cN:"meta",b:"!important"}]}}]};return{cI:!0,i:/[=\/|'\$]/,c:[e.CBCM,{cN:"selector-id",b:/#[A-Za-z0-9_-]+/},{cN:"selector-class",b:/\.[A-Za-z0-9_-]+/},{cN:"selector-attr",b:/\[/,e:/\]/,i:"$"},{cN:"selector-pseudo",b:/:(:)?[a-zA-Z0-9\_\-\+\(\)"'.]+/},{b:"@(font-face|page)",l:"[a-z-]+",k:"font-face page"},{b:"@",e:"[{;]",i:/:/,c:[{cN:"keyword",b:/\w+/},{b:/\s/,eW:!0,eE:!0,r:0,c:[e.ASM,e.QSM,e.CSSNM]}]},{cN:"selector-tag",b:c,r:0},{b:"{",e:"}",i:/\S/,c:[e.CBCM,t]}]}});hljs.registerLanguage("python",function(e){var r={keyword:"and elif is global as in if from raise for except finally print import pass return exec else break not with class assert yield try while continue del or def lambda async await nonlocal|10 None True False",built_in:"Ellipsis NotImplemented"},b={cN:"meta",b:/^(>>>|\.\.\.) /},c={cN:"subst",b:/\{/,e:/\}/,k:r,i:/#/},a={cN:"string",c:[e.BE],v:[{b:/(u|b)?r?'''/,e:/'''/,c:[b],r:10},{b:/(u|b)?r?"""/,e:/"""/,c:[b],r:10},{b:/(fr|rf|f)'''/,e:/'''/,c:[b,c]},{b:/(fr|rf|f)"""/,e:/"""/,c:[b,c]},{b:/(u|r|ur)'/,e:/'/,r:10},{b:/(u|r|ur)"/,e:/"/,r:10},{b:/(b|br)'/,e:/'/},{b:/(b|br)"/,e:/"/},{b:/(fr|rf|f)'/,e:/'/,c:[c]},{b:/(fr|rf|f)"/,e:/"/,c:[c]},e.ASM,e.QSM]},s={cN:"number",r:0,v:[{b:e.BNR+"[lLjJ]?"},{b:"\\b(0o[0-7]+)[lLjJ]?"},{b:e.CNR+"[lLjJ]?"}]},i={cN:"params",b:/\(/,e:/\)/,c:["self",b,s,a]};return c.c=[a,s,b],{aliases:["py","gyp"],k:r,i:/(<\/|->|\?)|=>/,c:[b,s,a,e.HCM,{v:[{cN:"function",bK:"def"},{cN:"class",bK:"class"}],e:/:/,i:/[${=;\n,]/,c:[e.UTM,i,{b:/->/,eW:!0,k:"None"}]},{cN:"meta",b:/^[\t ]*@/,e:/$/},{b:/\b(print|exec)\(/}]}});hljs.registerLanguage("objectivec",function(e){var t={cN:"built_in",b:"\\b(AV|CA|CF|CG|CI|CL|CM|CN|CT|MK|MP|MTK|MTL|NS|SCN|SK|UI|WK|XC)\\w+"},_={keyword:"int float while char export sizeof typedef const struct for union unsigned long volatile static bool mutable if do return goto void enum else break extern asm case short default double register explicit signed typename this switch continue wchar_t inline readonly assign readwrite self @synchronized id typeof nonatomic super unichar IBOutlet IBAction strong weak copy in out inout bycopy byref oneway __strong __weak __block __autoreleasing @private @protected @public @try @property @end @throw @catch @finally @autoreleasepool @synthesize @dynamic @selector @optional @required @encode @package @import @defs @compatibility_alias __bridge __bridge_transfer __bridge_retained __bridge_retain __covariant __contravariant __kindof _Nonnull _Nullable _Null_unspecified __FUNCTION__ __PRETTY_FUNCTION__ __attribute__ getter setter retain unsafe_unretained nonnull nullable null_unspecified null_resettable class instancetype NS_DESIGNATED_INITIALIZER NS_UNAVAILABLE NS_REQUIRES_SUPER NS_RETURNS_INNER_POINTER NS_INLINE NS_AVAILABLE NS_DEPRECATED NS_ENUM NS_OPTIONS NS_SWIFT_UNAVAILABLE NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_END NS_REFINED_FOR_SWIFT NS_SWIFT_NAME NS_SWIFT_NOTHROW NS_DURING NS_HANDLER NS_ENDHANDLER NS_VALUERETURN NS_VOIDRETURN",literal:"false true FALSE TRUE nil YES NO NULL",built_in:"BOOL dispatch_once_t dispatch_queue_t dispatch_sync dispatch_async dispatch_once"},i=/[a-zA-Z@][a-zA-Z0-9_]*/,n="@interface @class @protocol @implementation";return{aliases:["mm","objc","obj-c"],k:_,l:i,i:""}]}]},{cN:"class",b:"("+n.split(" ").join("|")+")\\b",e:"({|$)",eE:!0,k:n,l:i,c:[e.UTM]},{b:"\\."+e.UIR,r:0}]}});hljs.registerLanguage("php",function(e){var c={b:"\\$+[a-zA-Z_-ÿ][a-zA-Z0-9_-ÿ]*"},i={cN:"meta",b:/<\?(php)?|\?>/},t={cN:"string",c:[e.BE,i],v:[{b:'b"',e:'"'},{b:"b'",e:"'"},e.inherit(e.ASM,{i:null}),e.inherit(e.QSM,{i:null})]},a={v:[e.BNM,e.CNM]};return{aliases:["php3","php4","php5","php6"],cI:!0,k:"and include_once list abstract global private echo interface as static endswitch array null if endwhile or const for endforeach self var while isset public protected exit foreach throw elseif include __FILE__ empty require_once do xor return parent clone use __CLASS__ __LINE__ else break print eval new catch __METHOD__ case exception default die require __FUNCTION__ enddeclare final try switch continue endfor endif declare unset true false trait goto instanceof insteadof __DIR__ __NAMESPACE__ yield finally",c:[e.HCM,e.C("//","$",{c:[i]}),e.C("/\\*","\\*/",{c:[{cN:"doctag",b:"@[A-Za-z]+"}]}),e.C("__halt_compiler.+?;",!1,{eW:!0,k:"__halt_compiler",l:e.UIR}),{cN:"string",b:/<<<['"]?\w+['"]?$/,e:/^\w+;?$/,c:[e.BE,{cN:"subst",v:[{b:/\$\w+/},{b:/\{\$/,e:/\}/}]}]},i,{cN:"keyword",b:/\$this\b/},c,{b:/(::|->)+[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/},{cN:"function",bK:"function",e:/[;{]/,eE:!0,i:"\\$|\\[|%",c:[e.UTM,{cN:"params",b:"\\(",e:"\\)",c:["self",c,e.CBCM,t,a]}]},{cN:"class",bK:"class interface",e:"{",eE:!0,i:/[:\(\$"]/,c:[{bK:"extends implements"},e.UTM]},{bK:"namespace",e:";",i:/[\.']/,c:[e.UTM]},{bK:"use",e:";",c:[e.UTM]},{b:"=>"},t,a]}});hljs.registerLanguage("makefile",function(e){var i={cN:"variable",v:[{b:"\\$\\("+e.UIR+"\\)",c:[e.BE]},{b:/\$[@% 9 |

10 | {{"account_info"|i18n}} 11 |

12 | 24 | 25 | {% endblock content %} 26 | -------------------------------------------------------------------------------- /views/forum/acknowledgement.html: -------------------------------------------------------------------------------- 1 | {% extends "forum/base.html" %} 2 | 3 | {% block title %} 4 | Search - {{"title"|i18n}} 5 | {% endblock title %} 6 | 7 | {% block content %} 8 |
9 | 10 |

感谢以下赞助商

11 |
12 |
13 |

14 |

img
15 |
16 |
17 |

迅达云

18 |
19 |

从2016年1月起为Rust语言中文社区免费赞助服务器一台。特此感谢!

20 |
21 |

22 |
23 |
24 |
25 |

26 |

27 | img 28 | img 29 |
30 |
31 |
32 |

赛贝去中心化交易所 33 | & LongHash

34 |
35 |

从2019年5月起为Rust语言中文社区免费赞助服务器一台。特此感谢!

36 |
37 |

38 | 39 |
40 | {% endblock content %} 41 | -------------------------------------------------------------------------------- /views/forum/admin/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/miketang84/forustm/6739092ff14ed611391d0cbcff65de4296db6d93/views/forum/admin/.keep -------------------------------------------------------------------------------- /views/forum/admin_landing_page.html: -------------------------------------------------------------------------------- 1 | {% extends "forum/base.html" %} 2 | 3 | {% block title %} 4 | {{"section_rearrange"|i18n}} - {{"title"|i18n}} 5 | {% endblock title %} 6 | 7 | {% block content %} 8 | 14 | {% endblock content %} 15 | -------------------------------------------------------------------------------- /views/forum/arrange_sections.html: -------------------------------------------------------------------------------- 1 | {% extends "forum/base.html" %} 2 | 3 | {% block title %} 4 | {{"section_rearrange"|i18n}} - {{"title"|i18n}} 5 | {% endblock title %} 6 | 7 | {% block content %} 8 |
9 |

10 | {{"section_rearrange"|i18n}} 11 |

12 | 13 |
14 | {% for section in sections %} 15 | {{section.title}} 16 | 17 |
18 | {% endfor %} 19 | 20 | 21 |
22 |
23 | {% endblock content %} 24 | -------------------------------------------------------------------------------- /views/forum/article.html: -------------------------------------------------------------------------------- 1 | {% extends "forum/base.html" %} 2 | 3 | {% block title %} 4 | {{ article.title }} - {{"title"|i18n}} 5 | {% endblock title %} 6 | 7 | {% block content %} 8 | 9 | 10 | 11 | 12 | 13 |
14 |
15 | {% if article.stype == 0 %} 16 | < {{"return_section"|i18n}} 17 | {% else %} 18 | < {{"return_blog"|i18n}} 19 | {% endif %} 20 | 23 |

24 | {{ author.nickname }} 25 | 26 | {{"posted_at"|i18n}} {{article.created_time | zone8 }} 27 | 28 | {% if is_author or is_admin %} 29 | {% if article.stype == 0 %} 30 | {{"edit"|i18n}} 31 | {% else %} 32 | {{"edit"|i18n}} 33 | {% endif %} 34 | {% endif %} 35 |

36 |

37 | {% if article.tags %} 38 | Tags:{{ article.tags }} 39 | {% endif %} 40 |

41 |
42 | 43 |
44 | {{ article.content | safe }} 45 |
46 | 47 | {% if article.extlink != "" %} 48 | 51 |
52 | Ext Link: {{article.extlink}} 53 |
54 |
55 | {% endif %} 56 | 57 |
58 |
59 |

{{"comment_area"|i18n}}

60 | {{"write_comment"|i18n}} 61 |
62 |
63 | 64 | {% if comments | length == 0 %} 65 |

{{"no_comment"|i18n}}

66 | {% else %} 67 | {% for comment in comments %} 68 |
69 |
70 | {% if comment.author_id == author.id %} 71 | {{"author"|i18n}} 72 | {% endif %} 73 | 74 | {{ comment.nickname }} 75 | 76 | {{ comment.created_time | zone8 }} 77 | {% if is_login and user.id == comment.author_id or is_admin %} 78 | {{"delete"|i18n}} 79 | {% endif %} 80 | {% if is_login %} 81 | {{"reply"|i18n}} 82 | {% endif %} 83 |
84 |
85 | {{ comment.content | safe }} 86 |
87 |
88 | {% endfor %} 89 | {% endif %} 90 |
91 | 92 |
93 |
94 | {% for _ in range(end = total_page) %} 95 | 97 | {{ loop.index }} 98 | 99 | {% endfor %} 100 | {{"totally"|i18n}} {{ total_item }} {{"num_comments"|i18n}}, {{ total_page }} {{"page"|i18n}} 101 |
102 |
103 |
104 |
105 | 106 | 115 | {% endblock content %} 116 | -------------------------------------------------------------------------------- /views/forum/article_list_paging.html: -------------------------------------------------------------------------------- 1 | {% extends "forum/base.html" %} 2 | 3 | {% block title %} 4 | {{ s_title }} - {{"title"|i18n}} 5 | {% endblock title %} 6 | 7 | {% block content %} 8 |
9 |
10 |
11 |

{{ s_title }}

12 |
13 |
14 | 15 |
16 | {% if articles | length == 0 %} 17 |

{{"no_content"|i18n}}

18 | {% else %} 19 | 38 | {% endif %} 39 |
40 | 41 |
42 | {% for _ in range(end=total_page) %} 43 | 45 | {{ loop.index }} 46 | 47 | {% endfor %} 48 | {{"totally"|i18n}} {{ total_item }} {{"articles"|i18n}}, {{ total_page }} {{"page"|i18n}} 49 |
50 |
51 |
52 | {% endblock content %} 53 | -------------------------------------------------------------------------------- /views/forum/base.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | 10 | 11 | 12 | {% block title %}{% endblock title %} 13 | 14 | 15 | 16 | 17 | 20 |
21 | {% block content %}{% endblock content %} 22 |
23 | 26 | {% block script %}{% endblock script %} 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /views/forum/delete_article.html: -------------------------------------------------------------------------------- 1 | {% extends "forum/base.html" %} 2 | 3 | {% block title %} 4 | {{"delete_article"|i18n}} - {{"title"|i18n}} 5 | {% endblock title %} 6 | 7 | {% block content %} 8 |
9 |

10 | {{"delete_article"|i18n}} 11 |

12 |

{{"delete_article_prompt"|i18n}} 13 |
14 | {{article.title}} 15 |
16 | {{"yes_or_no"|i18n}} 17 |

18 | 19 |
20 | 21 | 22 |
23 |   {{"cancel"|i18n}} 24 |
25 |
26 | {% endblock content %} 27 | -------------------------------------------------------------------------------- /views/forum/delete_comment.html: -------------------------------------------------------------------------------- 1 | {% extends "forum/base.html" %} 2 | 3 | {% block title %} 4 | {{"delete_comment"|i18n}} - {{"title"|i18n}} 5 | {% endblock title %} 6 | 7 | {% block content %} 8 |
9 |

10 | {{"delete_comment"|i18n}} 11 |

12 |

{{"delete_comment_prompt"|i18n}} 13 |
14 | {{comment.content}} 15 |
16 | {{"yes_or_no"|i18n}} 17 |

18 | 19 |
20 | 21 | 22 |
23 |   {{"cancel"|i18n}} 24 |
25 |
26 | {% endblock content %} 27 | -------------------------------------------------------------------------------- /views/forum/edit_article.html: -------------------------------------------------------------------------------- 1 | {% extends "forum/base.html" %} 2 | 3 | {% block title %} 4 | {{"edit_article"|i18n}} - {{"title"|i18n}} 5 | {% endblock title %} 6 | 7 | {% block content %} 8 |
9 | {% if is_in_blog %} 10 |

11 | {{"edit_blog_article"|i18n}} 12 |

13 | {% else %} 14 |

15 | {{"edit_article"|i18n}} 16 |

17 | {% endif %} 18 | {% if is_in_blog %} 19 |
20 | {% else %} 21 | 22 | 31 |
32 | {% endif %} 33 | 34 | 35 |
36 | 37 |
38 | 39 |
40 | 41 |
42 | 43 |
44 |
45 | {% endblock content %} 46 | -------------------------------------------------------------------------------- /views/forum/edit_comment.html: -------------------------------------------------------------------------------- 1 | {% extends "forum/base.html" %} 2 | 3 | {% block title %} 4 | {{"edit_comment"|i18n}} - {{"title"|i18n}} 5 | {% endblock title %} 6 | 7 | {% block content %} 8 |
9 |

10 | {{"edit_comment"|i18n}} 11 |

12 |

{{"article"|i18n}} 13 | {{article.title}} 14 |

15 |
16 | 17 | 18 |
19 | 20 |
21 | 22 |
23 |
24 | {% endblock content %} 25 | -------------------------------------------------------------------------------- /views/forum/edit_section.html: -------------------------------------------------------------------------------- 1 | {% extends "forum/base.html" %} 2 | 3 | {% block title %} 4 | {{"edit_section"|i18n}} 5 | {% endblock title %} 6 | 7 | {% block content %} 8 |
9 |

{{"edit_section"|i18n}}

10 |
11 |
12 | 13 | 14 |
15 | 16 |
17 | 18 |
19 |
20 | {% endblock content %} 21 | -------------------------------------------------------------------------------- /views/forum/footer.html: -------------------------------------------------------------------------------- 1 | 27 | 28 | 37 | -------------------------------------------------------------------------------- /views/forum/header.html: -------------------------------------------------------------------------------- 1 |
2 | 10 | 11 |
12 | Search   13 | RSS   14 | {{"account"|i18n}} 15 |
16 |
17 |
18 | -------------------------------------------------------------------------------- /views/forum/index.html: -------------------------------------------------------------------------------- 1 | {% extends "forum/base.html" %} 2 | 3 | {% block title %} 4 | {{"title"|i18n}}-{{"index"|i18n}} 5 | {% endblock title %} 6 | 7 | {% block content %} 8 |
9 | 14 | 15 |
16 |
17 | {{"latest_articles"|i18n}} 18 |
19 | {% if articles | length == 0 %} 20 |

{{"no_content"|i18n}}

21 | {% else %} 22 |
23 | 37 |
38 | {% endif %} 39 |
40 |
41 | 42 |
43 |
44 | {{"latest_reply_articles"|i18n}} 45 |
46 | {% if reply_articles | length == 0 %} 47 |

{{"no_content"|i18n}}

48 | {% else %} 49 |
50 | 64 |
65 | {% endif %} 66 |
67 |
68 | 69 | 70 |
71 | 74 | {% if blog_articles | length == 0 %} 75 |

{{"no_content"|i18n}}

76 | {% else %} 77 |
78 | 89 |
90 | {% endif %} 91 |
92 |
93 | 94 |
95 |
96 | {{"sections"|i18n}} 97 |
98 | {% if sections | length == 0 %} 99 |

{{"no_content"|i18n}}

100 | {% else %} 101 |
102 |
    103 | {% for sec in sections %} 104 |
  • 105 | {{ sec.title }} 106 |
  • 107 | {% endfor %} 108 |
109 |
110 |
111 | {% endif %} 112 |
113 | 114 | 132 |
133 | {% endblock content %} 134 | -------------------------------------------------------------------------------- /views/forum/login_with3rd.html: -------------------------------------------------------------------------------- 1 | {% extends "forum/base.html" %} 2 | 3 | {% block title %} 4 | {{"login"|i18n}} - {{"title"|i18n}} 5 | {% endblock title %} 6 | 7 | {% block script %} 8 | {% endblock script %} 9 | 10 | {% block content %} 11 |
12 |

{{"login"|i18n}}

13 | 14 | 16 | 23 | 24 |
25 | {% endblock content %} 26 | -------------------------------------------------------------------------------- /views/forum/login_with_admin.html: -------------------------------------------------------------------------------- 1 | {% extends "forum/base.html" %} 2 | 3 | {% block title %} 4 | {{"login"|i18n}} - {{"title"|i18n}} 5 | {% endblock title %} 6 | 7 | {% block script %} 8 | {% endblock script %} 9 | 10 | {% block content %} 11 |
12 |

{{"login"|i18n}}

13 |
14 |
15 | 16 | 17 | 18 | 19 | 21 | 22 | 23 | 24 | 26 | 27 | 28 |
Account:
Password:
29 | 30 |
31 |
32 |
33 | {% endblock content %} 34 | -------------------------------------------------------------------------------- /views/forum/manage_section_view.html: -------------------------------------------------------------------------------- 1 | {% extends "forum/base.html" %} 2 | 3 | {% block title %} 4 | {{"section_rearrange"|i18n}} - {{"title"|i18n}} 5 | {% endblock title %} 6 | 7 | {% block content %} 8 |
9 |

10 | Manage Section View 11 |

12 | {% for section in sections %} 13 |

14 | {{section.title}}   15 | EditSection   16 | Manage   17 |

18 |
19 | {% endfor %} 20 |
21 | {% endblock content %} 22 | -------------------------------------------------------------------------------- /views/forum/manage_section_view_articles.html: -------------------------------------------------------------------------------- 1 | {% extends "forum/base.html" %} 2 | 3 | {% block title %} 4 | Manage Section View - {{"title"|i18n}} 5 | {% endblock title %} 6 | 7 | {% block content %} 8 |
9 | < back 10 | 11 |

12 | Section: {{section.title}} 13 |

14 | 15 | {% if articles | length == 0 %} 16 |

{{"no_content"|i18n}}

17 | {% else %} 18 | Article ID, Article Title, Article Weight 19 | {% for article in articles %} 20 |

{{article.article_id}}, {{article.title}}, {{article.weight}} 21 | Delete 22 |

23 |
24 | {% endfor %} 25 | {% endif %} 26 | 27 |
28 | 29 | 30 |
31 | 32 |
33 | 34 |
35 | 36 |
37 | {% endblock content %} 38 | -------------------------------------------------------------------------------- /views/forum/new_article.html: -------------------------------------------------------------------------------- 1 | {% extends "forum/base.html" %} 2 | 3 | {% block title %} 4 | {{"new_article"|i18n}} - {{"title"|i18n}} 5 | {% endblock title %} 6 | 7 | {% block content %} 8 |
9 | {% if is_in_blog %} 10 |

11 | {{"new_blog_post"|i18n}} 12 |

13 | {% else %} 14 |

15 | {{"new_article"|i18n}} 16 |

17 | {% endif %} 18 | {% if is_in_blog %} 19 |
20 | 21 | {% else %} 22 | 23 | 32 | 33 |
34 | {% endif %} 35 | 36 | 37 |
38 | 39 |
40 | 41 |
42 | 43 |
44 | 45 |
46 |
47 | {% endblock content %} 48 | -------------------------------------------------------------------------------- /views/forum/new_comment.html: -------------------------------------------------------------------------------- 1 | {% extends "forum/base.html" %} 2 | 3 | {% block title %} 4 | {{"new_comment"|i18n}} - {{"title"|i18n}} 5 | {% endblock title %} 6 | 7 | {% block content %} 8 | 9 |
10 |

11 | {{"new_comment"|i18n}} 12 |

13 |

{{"new_reply_prompt"|i18n}}
14 | 《{{article.title}}》 15 |

16 |
17 | 18 | {% if reply_comment %} 19 | 20 | {% endif %} 21 | 28 |
29 | 30 |
31 |
32 | 33 | {% endblock content %} 34 | -------------------------------------------------------------------------------- /views/forum/new_section.html: -------------------------------------------------------------------------------- 1 | {% extends "forum/base.html" %} 2 | 3 | {% block title %} 4 | {{"new_section"|i18n}} 5 | {% endblock title %} 6 | 7 | {% block content %} 8 |
9 |

{{"new_section"|i18n}}

10 |
11 |
12 | 13 |
14 | 15 |
16 | 17 |
18 |
19 | {% endblock content %} 20 | -------------------------------------------------------------------------------- /views/forum/search_result.html: -------------------------------------------------------------------------------- 1 | {% extends "forum/base.html" %} 2 | 3 | {% block title %} 4 | Search - {{"title"|i18n}} 5 | {% endblock title %} 6 | 7 | {% block content %} 8 |
9 | 10 |
11 | 12 | 13 |
14 | 15 |
16 |

Search Results:

17 | {% for doc in docs %} 18 |

{{ doc.created_time | zone8 }}   {{doc.title}}

19 | {% endfor %} 20 |
21 | 22 |
23 | {% endblock content %} 24 | -------------------------------------------------------------------------------- /views/forum/section.html: -------------------------------------------------------------------------------- 1 | {% extends "forum/base.html" %} 2 | 3 | {% block title %} 4 | {{ section.title }} - {{"title"|i18n}} 5 | {% endblock title %} 6 | 7 | {% block content %} 8 |
9 |
10 |
11 |

{{ section.title }}

12 | {% if is_myown_blog %} 13 | {{"write_blog"|i18n}} 14 | {% else %} 15 | {{"post_article"|i18n}} 16 | {% endif %} 17 |
18 |

19 | {{ section.description }} 20 |

21 |
22 | 23 |
24 | {% if articles | length == 0 %} 25 |

{{"no_content"|i18n}}

26 | {% else %} 27 |
    28 | {% for article_with_stats in articles %} 29 |
  • 30 | 31 | {{ article_with_stats.article.title }} 32 | ({{ article_with_stats.viewtimes }},{{ article_with_stats.article.comment_count }}) 33 |
    34 |
    35 | 36 | {{ article_with_stats.article.tags }} 37 | {{ article_with_stats.article.author_name }} 38 | {{ article_with_stats.article.created_time | zone8 }} 39 | {% if is_admin %} 40 | {{"delete"|i18n}} 41 | {{"edit"|i18n}} 42 | {% endif %} 43 | 44 |
    45 |
  • 46 | {% endfor %} 47 |
48 | {% endif %} 49 |
50 | 51 |
52 | {% for _ in range(end=total_page) %} 53 | 55 | {{ loop.index }} 56 | 57 | {% endfor %} 58 | {{"totally"|i18n}} {{ total_item }} {{"articles"|i18n}}, {{ total_page }} {{"page"|i18n}} 59 |
60 |
61 |
62 | {% endblock content %} 63 | -------------------------------------------------------------------------------- /views/forum/user_change_pwd_page.html: -------------------------------------------------------------------------------- 1 | {% extends "forum/base.html" %} 2 | 3 | {% block title %} 4 | Modify Password - {{"title"|i18n}} 5 | {% endblock title %} 6 | 7 | {% block content %} 8 |
9 |

10 | Modify Password 11 |

12 |
13 | 14 |
15 | 16 |
17 | 18 |
19 |
20 | {% endblock content %} 21 | -------------------------------------------------------------------------------- /views/forum/user_modifynickname_page.html: -------------------------------------------------------------------------------- 1 | {% extends "forum/base.html" %} 2 | 3 | {% block title %} 4 | Modify Nickname - {{"title"|i18n}} 5 | {% endblock title %} 6 | 7 | {% block content %} 8 |
9 |

10 | Modify Nickname 11 |

12 |
13 | 14 | 15 |
16 | 17 |
18 |
19 | {% endblock content %} 20 | --------------------------------------------------------------------------------