add a preferred_url option
This commit is contained in:
parent
a9e3490478
commit
81fda6e1c8
|
@ -67,6 +67,7 @@ This is the main configuration file. The file will be compiled statically into t
|
||||||
"plugin_identifier": "com.example.change.this.to.whatever.you.like",
|
"plugin_identifier": "com.example.change.this.to.whatever.you.like",
|
||||||
"posts_per_page": 5,
|
"posts_per_page": 5,
|
||||||
"cache_maxage": 86400,
|
"cache_maxage": 86400,
|
||||||
|
"preferred_url": "<your_url>",
|
||||||
"redirects": {
|
"redirects": {
|
||||||
"/foo": "/bar",
|
"/foo": "/bar",
|
||||||
...
|
...
|
||||||
|
@ -90,6 +91,8 @@ This is the main configuration file. The file will be compiled statically into t
|
||||||
|
|
||||||
`plugin_identifier`: Used in Standard Notes to distinguish plugins.
|
`plugin_identifier`: Used in Standard Notes to distinguish plugins.
|
||||||
|
|
||||||
|
`preferred_url`: OPTIONAL. The preferred URL to use for the options "Open Post" and "Open Blog" (and for these options ONLY) in the Standard Notes Actions menu. Must NOT include a trailing `/`. This is useful if you publish your blog at `https://your_domain.com` but use a `workers.dev` domain for your Standard Notes plugin address.
|
||||||
|
|
||||||
`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.
|
`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.
|
`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.
|
||||||
|
|
14
src/sn.rs
14
src/sn.rs
|
@ -30,6 +30,7 @@ async fn get_actions(_req: Request, url: Url) -> MyResult<Response> {
|
||||||
verify_secret!(url, params);
|
verify_secret!(url, params);
|
||||||
|
|
||||||
let origin = url.origin();
|
let origin = url.origin();
|
||||||
|
let preferred_url = crate::CONFIG.preferred_url.clone().unwrap_or(origin.clone());
|
||||||
let mut actions = vec![];
|
let mut actions = vec![];
|
||||||
|
|
||||||
// Show different options depending on whether the post already exists
|
// Show different options depending on whether the post already exists
|
||||||
|
@ -63,10 +64,10 @@ async fn get_actions(_req: Request, url: Url) -> MyResult<Response> {
|
||||||
content_types: vec![ContentType::Note],
|
content_types: vec![ContentType::Note],
|
||||||
access_type: Some(AccessType::Decrypted)
|
access_type: Some(AccessType::Decrypted)
|
||||||
});
|
});
|
||||||
|
|
||||||
actions.push(Action {
|
actions.push(Action {
|
||||||
label: "Open Post".into(),
|
label: "Open Post".into(),
|
||||||
url: format!("{}/{}/", origin, post.unwrap().url),
|
url: format!("{}/{}/", preferred_url, post.unwrap().url),
|
||||||
verb: Verb::Show,
|
verb: Verb::Show,
|
||||||
context: Context::Item,
|
context: Context::Item,
|
||||||
content_types: vec![ContentType::Note],
|
content_types: vec![ContentType::Note],
|
||||||
|
@ -74,6 +75,15 @@ async fn get_actions(_req: Request, url: Url) -> MyResult<Response> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
actions.push(Action {
|
||||||
|
label: "Open Blog".into(),
|
||||||
|
url: preferred_url.clone(),
|
||||||
|
verb: Verb::Show,
|
||||||
|
context: Context::Item,
|
||||||
|
content_types: vec![ContentType::Note],
|
||||||
|
access_type: None
|
||||||
|
});
|
||||||
|
|
||||||
let info = ActionsExtension {
|
let info = ActionsExtension {
|
||||||
identifier: CONFIG.plugin_identifier.clone(),
|
identifier: CONFIG.plugin_identifier.clone(),
|
||||||
name: CONFIG.title.clone(),
|
name: CONFIG.title.clone(),
|
||||||
|
|
|
@ -164,7 +164,10 @@ pub struct Config {
|
||||||
// UNLIKE in article headers
|
// UNLIKE in article headers
|
||||||
pub redirects: Option<HashMap<String, String>>,
|
pub redirects: Option<HashMap<String, String>>,
|
||||||
// Additional remote resource proxy whitelist
|
// Additional remote resource proxy whitelist
|
||||||
pub extra_remote_proxy_whitelist: Option<Vec<String>>
|
pub extra_remote_proxy_whitelist: Option<Vec<String>>,
|
||||||
|
// Preferred URL of the blog for "Open Post" and "Open Blog" options in SN
|
||||||
|
// Must NOT include the trailing "/"
|
||||||
|
pub preferred_url: Option<String>
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_maxage() -> u64 {
|
fn default_maxage() -> u64 {
|
||||||
|
|
Loading…
Reference in a new issue