mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-05-26 20:49:55 +00:00
47 lines
1.6 KiB
Rust
47 lines
1.6 KiB
Rust
//! one true function for returning the conduwuit version with the necessary
|
|
//! CONDUWUIT_VERSION_EXTRA env variables used if specified
|
|
//!
|
|
//! Set the environment variable `CONDUWUIT_VERSION_EXTRA` to any UTF-8 string
|
|
//! to include it in parenthesis after the SemVer version. A common value are
|
|
//! git commit hashes.
|
|
|
|
use std::sync::OnceLock;
|
|
|
|
pub const BRANDING: &str = "continuwuity";
|
|
pub const ROUTE_PREFIX: &str = "/_continuwuity";
|
|
pub const WEBSITE: &str = "https://continuwuity.org";
|
|
pub const SEMANTIC: &str = env!("CARGO_PKG_VERSION");
|
|
|
|
static VERSION: OnceLock<String> = OnceLock::new();
|
|
static VERSION_UA: OnceLock<String> = OnceLock::new();
|
|
static USER_AGENT: OnceLock<String> = OnceLock::new();
|
|
static USER_AGENT_MEDIA: OnceLock<String> = OnceLock::new();
|
|
|
|
#[inline]
|
|
pub fn version() -> &'static str { VERSION.get_or_init(init_version) }
|
|
|
|
#[inline]
|
|
pub fn version_ua() -> &'static str { VERSION_UA.get_or_init(init_version_ua) }
|
|
|
|
#[inline]
|
|
pub fn user_agent() -> &'static str { USER_AGENT.get_or_init(init_user_agent) }
|
|
|
|
#[inline]
|
|
pub fn user_agent_media() -> &'static str { USER_AGENT_MEDIA.get_or_init(init_user_agent_media) }
|
|
|
|
fn init_user_agent() -> String { format!("{BRANDING}/{} (bot; +{WEBSITE})", version_ua()) }
|
|
|
|
fn init_user_agent_media() -> String {
|
|
format!("{BRANDING}/{} (embedbot; facebookexternalhit/1.1; +{WEBSITE})", version_ua())
|
|
}
|
|
|
|
fn init_version_ua() -> String {
|
|
conduwuit_build_metadata::version_tag()
|
|
.map_or_else(|| SEMANTIC.to_owned(), |extra| format!("{SEMANTIC}+{extra}"))
|
|
}
|
|
|
|
fn init_version() -> String {
|
|
conduwuit_build_metadata::version_tag()
|
|
.map_or_else(|| SEMANTIC.to_owned(), |extra| format!("{SEMANTIC} ({extra})"))
|
|
}
|