drop rbtag and use our own hand-rolled implementation

because we need to update build timestamp each time anything related to
rendering is changed. The rbtag crate only supports git commit times.

Also, reproducible build isn't exactly a goal of this project.
This commit is contained in:
Peter Cai 2020-04-12 17:25:55 +08:00
parent 54ca223ed6
commit 2ee88e11b0
No known key found for this signature in database
GPG Key ID: 71F5FB4E4F3FD54F
6 changed files with 24 additions and 49 deletions

46
Cargo.lock generated
View File

@ -133,7 +133,7 @@ checksum = "030a733c8287d6213886dd487564ff5c8f6aae10278b3588ed177f9d18f8d231"
dependencies = [
"proc-macro2 1.0.10",
"quote 1.0.3",
"syn 1.0.17",
"syn",
"synstructure",
]
@ -205,7 +205,7 @@ dependencies = [
"proc-macro-hack",
"proc-macro2 1.0.10",
"quote 1.0.3",
"syn 1.0.17",
"syn",
]
[[package]]
@ -317,7 +317,6 @@ dependencies = [
"lazy_static",
"mime_guess",
"pulldown-cmark",
"rbtag",
"serde",
"serde_json",
"wasm-bindgen",
@ -356,7 +355,7 @@ dependencies = [
"pest_meta",
"proc-macro2 1.0.10",
"quote 1.0.3",
"syn 1.0.17",
"syn",
]
[[package]]
@ -429,26 +428,6 @@ dependencies = [
"proc-macro2 1.0.10",
]
[[package]]
name = "rbtag"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72c64936fcc0b811890a9d90020f3df5cec9c604efde88af7db6a35d365132a3"
dependencies = [
"rbtag_derive",
]
[[package]]
name = "rbtag_derive"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b75511b710ccca8adbb211e04763bd8c78fed585b0ec188a20ed9b0dd95567c4"
dependencies = [
"proc-macro2 0.4.30",
"quote 0.6.13",
"syn 0.15.44",
]
[[package]]
name = "redox_syscall"
version = "0.1.56"
@ -490,7 +469,7 @@ checksum = "9e549e3abf4fb8621bd1609f11dfc9f5e50320802273b12f3811a67e6716ea6c"
dependencies = [
"proc-macro2 1.0.10",
"quote 1.0.3",
"syn 1.0.17",
"syn",
]
[[package]]
@ -516,17 +495,6 @@ dependencies = [
"opaque-debug",
]
[[package]]
name = "syn"
version = "0.15.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ca4b3b69a77cbe1ffc9e198781b7acb0c7365a883670e8f1c1bc66fba79a5c5"
dependencies = [
"proc-macro2 0.4.30",
"quote 0.6.13",
"unicode-xid 0.1.0",
]
[[package]]
name = "syn"
version = "1.0.17"
@ -546,7 +514,7 @@ checksum = "67656ea1dc1b41b1451851562ea232ec2e5a80242139f7e679ceccfb5d61f545"
dependencies = [
"proc-macro2 1.0.10",
"quote 1.0.3",
"syn 1.0.17",
"syn",
"unicode-xid 0.2.0",
]
@ -621,7 +589,7 @@ dependencies = [
"log",
"proc-macro2 1.0.10",
"quote 1.0.3",
"syn 1.0.17",
"syn",
"wasm-bindgen-shared",
]
@ -668,7 +636,7 @@ checksum = "d68a5b36eef1be7868f668632863292e37739656a80fc4b9acec7b0bd35a4931"
dependencies = [
"proc-macro2 1.0.10",
"quote 1.0.3",
"syn 1.0.17",
"syn",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]

View File

@ -27,7 +27,6 @@ include_dir = "0.5"
js-sys = "0.3"
mime_guess = "2.0"
pulldown-cmark = { version = "0.7", default-features = false }
rbtag = "0.3"
serde = { version = "1.0", features = [ "derive" ] }
serde_json = "1.0"
wasm-bindgen = "0.2"

View File

@ -1,17 +1,31 @@
extern crate serde_json;
use std::io::prelude::*;
use std::time::*;
fn main() {
println!("cargo:rerun-if-changed=config.json");
println!("cargo:rerun-if-changed=src");
println!("cargo:rerun-if-changed=Cargo.toml");
// Load theme name from config.json and output code to load the theme via include_dir!
let config: serde_json::Value =
serde_json::from_str(&std::fs::read_to_string("./config.json").unwrap()).unwrap();
generate_build_timestamp();
generate_theme_loader(&config);
generate_hljs_loader(&config);
}
fn generate_build_timestamp() {
let build_time = format!(
"pub const BUILD_TIMESTAMP: u64 = {};",
SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap().as_secs());
let out_path = std::path::PathBuf::from(std::env::var("OUT_DIR").unwrap());
let mut out_file = std::fs::File::create(out_path.join("build_timestamp.rs")).unwrap();
out_file.write(build_time.as_bytes()).unwrap();
out_file.sync_data().unwrap();
}
fn generate_theme_loader(config: &serde_json::Value) {
let theme_name = match config.get("theme") {
Some(name) => name,
@ -25,8 +39,6 @@ fn generate_theme_loader(config: &serde_json::Value) {
}
fn generate_hljs_loader(config: &serde_json::Value) {
println!("cargo:rerun-if-changed=src/hljs_tpl.rs");
let highlight_lang = match config.get("hljs") {
Some(val) => val,
None => panic!("Please specify what language for hljs to support in `config.json` with `hljs`")

View File

@ -7,7 +7,6 @@
use crate::store;
use crate::utils::*;
use pulldown_cmark::*;
use rbtag::BuildDateTime;
use serde::{Serialize, Deserialize};
use std::vec::Vec;
@ -120,7 +119,7 @@ lazy_static! {
// Whenever this is changed, all cache will be invalided
// Use build timestamp string
static ref CACHE_VERSION: String = {
format!("{}", BuildTag{}.get_build_timestamp())
format!("{}", BUILD_TIMESTAMP)
};
}

View File

@ -6,7 +6,6 @@ use chrono::NaiveDateTime;
use handlebars::Handlebars;
use include_dir::{include_dir, Dir};
use js_sys::{Date, Uint8Array};
use rbtag::BuildDateTime;
use serde::Serialize;
use std::vec::Vec;
use web_sys::*;
@ -111,7 +110,7 @@ lazy_static! {
}
handlebars_helper!(cur_year: | | Date::new_0().get_full_year());
handlebars_helper!(build_num: | | BuildTag{}.get_build_timestamp());
handlebars_helper!(build_num: | | BUILD_TIMESTAMP);
handlebars_helper!(format_date: |date: u64, format: str| {
NaiveDateTime::from_timestamp(date as i64, 0).format(format).to_string()
});

View File

@ -1,7 +1,6 @@
use cfg_if::cfg_if;
use serde::Deserialize;
use js_sys::*;
use rbtag::BuildDateTime;
use wasm_bindgen::prelude::*;
use wasm_bindgen_futures::*;
use web_sys::*;
@ -158,5 +157,4 @@ pub struct Config {
pub posts_per_page: usize
}
#[derive(BuildDateTime)]
pub struct BuildTag;
include!(concat!(env!("OUT_DIR"), "/build_timestamp.rs"));