diff options
| author | Fuwn <[email protected]> | 2022-04-14 23:29:14 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2022-04-14 23:29:14 -0700 |
| commit | a10670beb585c6b503583210b6db56b12b3c4f8a (patch) | |
| tree | a92bea3f1722935c20f597b1afa1e720e823adca /src | |
| parent | refactor: move route related functions (diff) | |
| download | locus-a10670beb585c6b503583210b6db56b12b3c4f8a.tar.xz locus-a10670beb585c6b503583210b6db56b12b3c4f8a.zip | |
refactor(quotes): move quotes to json file
Diffstat (limited to 'src')
| -rw-r--r-- | src/constants.rs | 55 | ||||
| -rw-r--r-- | src/macros.rs | 10 | ||||
| -rw-r--r-- | src/main.rs | 3 | ||||
| -rw-r--r-- | src/modules.rs | 3 |
4 files changed, 10 insertions, 61 deletions
diff --git a/src/constants.rs b/src/constants.rs deleted file mode 100644 index 27c80bd..0000000 --- a/src/constants.rs +++ /dev/null @@ -1,55 +0,0 @@ -// This file is part of Locus <https://github.com/gemrest/locus>. -// Copyright (C) 2022-2022 Fuwn <[email protected]> -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, version 3. -// -// This program is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see <http://www.gnu.org/licenses/>. -// -// Copyright (C) 2022-2022 Fuwn <[email protected]> -// SPDX-License-Identifier: GPL-3.0-only - -pub const QUOTES: &[&str] = &[ - "That brain of mine is something more than merely mortal; as time will \ - show. - Ada Lovelace", - "Forget this world and all its troubles and if possible its multitudinous \ - Charlatans — everything in short but the Enchantress of Numbers. - Ada \ - Lovelace", - "If you can't give me poetry, can't you give me poetical science? - Ada \ - Lovelace", - "What I cannot create, I do not understand. - Richard P. Feynman", - "Know how to solve every problem that has been solved. - Richard P. Feynman", - "Teach principles, not formulas. - Richard P. Feynman", - "I learned very early the difference between knowing the name of something \ - and knowing something. - Richard P. Feynman", - "Scientists are explorers. Philosophers are tourists. - Richard P. Feynman", - "If you thought that science was certain — Well, that is just an error on \ - your part. - Richard P. Feynman", - "Talk is cheap, Show me the code. - Linus Torvalds", - "I like offending people, because I think people who get offended should be \ - offended. - Linus Torvalds", - "Only wimps use tape backup. REAL men just upload their important stuff on \ - ftp and let the rest of the world mirror it. - Linus Torvalds", - "Intelligence is the ability to avoid doing work, yet getting the work \ - done. - Linus Torvalds", - "Programming is not a science. Programming is a craft. - Richard Stallman", - "I did write some code in Java once, but that was the island in Indonesia. \ - - Richard Stallman", - "Free software' is a matter of liberty, not price. To understand the \ - concept, you should think of 'free' as in 'free speech,' not as in 'free \ - beer'. - Richard Stallman", - "You can use any editor you want, but remember that vi vi vi is the text \ - editor of the beast. - Richard Stallman", - "Free software is software that respects your freedom and the social \ - solidarity of your community. So it's free as in freedom. - Richard \ - Stallman", - "Sharing is good, and with digital technology, sharing is easy. - Richard \ - Stallman", -]; diff --git a/src/macros.rs b/src/macros.rs index f65a901..0eaa2f1 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -23,7 +23,15 @@ macro_rules! success { Main { body: &$body, hits: &crate::route::hits_from($context.url.path()), - quote: QUOTES.choose(&mut rand::thread_rng()).unwrap(), + quote: { + use rand::seq::SliceRandom; + + let quotes: Vec<String> = + serde_json::from_str(include_str!("../content/json/quotes.json")) + .unwrap(); + + "es.choose(&mut rand::thread_rng()).unwrap().to_string() + }, commit: &format!("/tree/{}", env!("VERGEN_GIT_SHA")), mini_commit: env!("VERGEN_GIT_SHA").get(0..5).unwrap_or("UNKNOWN"), } diff --git a/src/main.rs b/src/main.rs index 15da848..58ee800 100644 --- a/src/main.rs +++ b/src/main.rs @@ -29,7 +29,6 @@ #![recursion_limit = "128"] #![allow(clippy::cast_precision_loss)] -mod constants; mod macros; mod modules; mod route; @@ -39,9 +38,7 @@ extern crate log; use std::{collections::HashMap, lazy::SyncLazy, sync::Mutex}; -use constants::QUOTES; use pickledb::PickleDb; -use rand::seq::SliceRandom; use route::track_mount; use tokio::time::Instant; use windmark::{Response, Router}; diff --git a/src/modules.rs b/src/modules.rs index 7e8a5bb..9cf4c57 100644 --- a/src/modules.rs +++ b/src/modules.rs @@ -22,10 +22,9 @@ use std::{ io::Read, }; -use rand::seq::SliceRandom; use windmark::Response; -use crate::{success, track_mount, Main, QUOTES}; +use crate::{success, track_mount, Main}; #[allow(clippy::too_many_lines)] pub fn multi_blog(router: &mut windmark::Router) { |