aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXe Iaso <me@christine.website>2023-01-05 16:14:29 -0500
committerXe Iaso <me@christine.website>2023-01-05 16:14:29 -0500
commit9e8c900e151c5e0637630b8fecb334314e52a2cc (patch)
tree5333ed338c7480dcf0501a304a4a3657076c3c09
parent51bd2d03837cab9ee97d81a5f6cf5ebde6adb4c2 (diff)
downloadxesite-9e8c900e151c5e0637630b8fecb334314e52a2cc.tar.xz
xesite-9e8c900e151c5e0637630b8fecb334314e52a2cc.zip
first attempt at multiple author supportauthors
Signed-off-by: Xe Iaso <me@christine.website>
-rw-r--r--src/app/config.rs21
-rw-r--r--src/handlers/api.rs10
-rw-r--r--src/handlers/json_ld.rs14
-rw-r--r--src/handlers/mod.rs1
-rw-r--r--src/main.rs10
5 files changed, 41 insertions, 15 deletions
diff --git a/src/app/config.rs b/src/app/config.rs
index d3d93ca..cabab40 100644
--- a/src/app/config.rs
+++ b/src/app/config.rs
@@ -30,8 +30,14 @@ pub struct Config {
pub pronouns: Vec<PronounSet>,
}
+fn schema_pronoun_set_type() -> String {
+ "https://xeiaso.net/api/json-ld/PronounSet".to_string()
+}
+
#[derive(Clone, Deserialize, Serialize, Default)]
pub struct PronounSet {
+ #[serde(rename = "@type", default = "schema_pronoun_set_type")]
+ pub schema_type: String,
nominative: String,
accusative: String,
#[serde(rename = "possessiveDeterminer")]
@@ -119,8 +125,10 @@ impl Default for StockKind {
}
}
-fn schema_context() -> String {
- "http://schema.org/".to_string()
+fn schema_person_context() -> serde_json::Value {
+ serde_json::json!(["https://schema.org/", {
+ "pronouns": { "@type": "https://xeiaso.net/api/json-ld/PronounSet", },
+ }])
}
fn schema_person_type() -> String {
@@ -129,8 +137,8 @@ fn schema_person_type() -> String {
#[derive(Clone, Deserialize, Serialize, Default)]
pub struct Author {
- #[serde(rename = "@context", default = "schema_context")]
- pub context: String,
+ #[serde(rename = "@context", default = "schema_person_context")]
+ pub context: serde_json::Value,
#[serde(rename = "@type", default = "schema_person_type")]
pub schema_type: String,
pub name: String,
@@ -140,12 +148,13 @@ pub struct Author {
pub pic_url: Option<String>,
#[serde(rename = "inSystem", skip_serializing)]
pub in_system: bool,
- #[serde(rename = "jobTitle")]
+ #[serde(rename = "jobTitle", skip_serializing_if = "String::is_empty")]
pub job_title: String,
- #[serde(rename = "sameAs")]
+ #[serde(rename = "sameAs", skip_serializing_if = "Vec::is_empty")]
pub same_as: Vec<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub url: Option<String>,
+ pub pronouns: PronounSet,
}
#[derive(Clone, Deserialize, Serialize, Default)]
diff --git a/src/handlers/api.rs b/src/handlers/api.rs
index 828f93c..af94f68 100644
--- a/src/handlers/api.rs
+++ b/src/handlers/api.rs
@@ -1,12 +1,12 @@
use crate::{
- app::{config::Job, PronounSet, State},
+ app::{config::Author, PronounSet, State},
handlers::Result,
post::Post,
};
use axum::extract::{Extension, Json, Path};
use lazy_static::lazy_static;
use prometheus::{opts, register_int_counter_vec, IntCounterVec};
-use std::sync::Arc;
+use std::{collections::HashMap, sync::Arc};
lazy_static! {
static ref BLOG: IntCounterVec = register_int_counter_vec!(
@@ -23,14 +23,14 @@ lazy_static! {
#[axum_macros::debug_handler]
#[instrument(skip(state))]
-pub async fn salary_transparency(Extension(state): Extension<Arc<State>>) -> Json<Vec<Job>> {
+pub async fn authors(Extension(state): Extension<Arc<State>>) -> Json<HashMap<String, Author>> {
super::HIT_COUNTER
- .with_label_values(&["salary_transparency_json"])
+ .with_label_values(&["authors_json"])
.inc();
let state = state.clone();
let cfg = state.cfg.clone();
- Json(cfg.job_history.clone())
+ Json(cfg.authors.clone())
}
#[axum_macros::debug_handler]
diff --git a/src/handlers/json_ld.rs b/src/handlers/json_ld.rs
new file mode 100644
index 0000000..07148dc
--- /dev/null
+++ b/src/handlers/json_ld.rs
@@ -0,0 +1,14 @@
+use axum::extract::Json;
+use serde_json::{json, Value};
+
+pub async fn pronoun_set() -> Json<Value> {
+ Json(json!({
+ "@type": "PronounSet",
+ "nominative": "string",
+ "accusative": "string",
+ "possessiveDeterminer": "string",
+ "possessive": "string",
+ "reflexive": "string",
+ "singular": "boolean",
+ }))
+}
diff --git a/src/handlers/mod.rs b/src/handlers/mod.rs
index 7284ec9..48a1b60 100644
--- a/src/handlers/mod.rs
+++ b/src/handlers/mod.rs
@@ -16,6 +16,7 @@ pub mod api;
pub mod blog;
pub mod feeds;
pub mod gallery;
+pub mod json_ld;
pub mod talks;
fn weekday_to_name(w: Weekday) -> &'static str {
diff --git a/src/main.rs b/src/main.rs
index aaf4ea4..d4b5692 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -157,14 +157,16 @@ async fn main() -> Result<()> {
),
)
// api
+ .route("/api/authors", get(handlers::api::authors))
.route("/api/pronouns", get(handlers::api::pronouns))
.route("/api/new_post", get(handlers::feeds::new_post))
- .route(
- "/api/salary_transparency.json",
- get(handlers::api::salary_transparency),
- )
.route("/api/blog/:name", get(handlers::api::blog))
.route("/api/talks/:name", get(handlers::api::talk))
+ // json-ld metadata
+ .route(
+ "/api/json-ld/PronounSet",
+ get(handlers::json_ld::pronoun_set),
+ )
// static pages
.route("/", get(handlers::index))
.route("/contact", get(handlers::contact))