support cache-control for static resources

Peter Cai 3 years ago
parent e6df5544f4
commit 44ca2f6de3
No known key found for this signature in database
GPG Key ID: 71F5FB4E4F3FD54F

@ -66,6 +66,7 @@ This is the main configuration file. The file will be compiled statically into t
"description": "<description>",
"plugin_identifier": "",
"posts_per_page": 5,
"cache_maxage": 86400,
"redirects": {
"/foo": "/bar",
@ -87,6 +88,8 @@ This is the main configuration file. The file will be compiled statically into t
`redirects`: OPTIONAL. A map of URLs where the key will be mapped to the value by Paprika using 301 redirects. This is mainly useful for migration from another blogging platform.
`cache_maxage`: OPTIONAL. A value in seconds determining how long the browser should cache static resources from the blog. If omitted, the default value is a week.
`hljs`: An array of language support from `highlight.js` to be included in the final binary. The full `highlight.js` is notoriously huge and there's really no reason to include a bazillion languages you will never actually use in your blog posts. This will be read by `` to generate a JS shim that will load all languages in the array to the final binary via `webpack` support for `require`.
Configuration: theme_config.json

@ -43,6 +43,10 @@ lazy_static! {
pub static ref CONFIG: utils::Config = {
pub static ref CACHE_CONTROL_STATIC_FILE: String = {
format!("max-age={}", CONFIG.cache_maxage)
fn build_routes() -> router::Router {
@ -97,7 +101,8 @@ async fn proxy_remote_image(req: Request, url: Url) -> MyResult<Response> {
"Content-Type" => &get_header!(remote_headers, "content-type")
"Content-Type" => &get_header!(remote_headers, "content-type"),

@ -29,7 +29,8 @@ async fn serve_static(_req: Request, url: Url) -> MyResult<Response> {
"Content-Type" => mime_guess::from_path(path).first().unwrap().essence_str()
"Content-Type" => mime_guess::from_path(path).first().unwrap().essence_str(),
"Cache-Control" => &crate::CACHE_CONTROL_STATIC_FILE
} else {

@ -156,10 +156,17 @@ pub struct Config {
pub plugin_identifier: String,
// How many posts to show in one page
pub posts_per_page: usize,
// The browser cache timeout for static resources in seconds
#[serde(default = "default_maxage")]
pub cache_maxage: u64,
// Hard-coded redirects (for migrating old articles and such)
// Paths here MUST include the starting "/"
// UNLIKE in article headers
pub redirects: Option<HashMap<String, String>>
fn default_maxage() -> u64 {
60 * 60 * 24 * 7 // default to a week
include!(concat!(env!("OUT_DIR"), "/"));