Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Dan thumbnail update#1297

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
chillenberger merged 5 commits intomasterfromdan-thumbnail-update
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
NextNext commit
default blog post and site thumbnail
  • Loading branch information
@chillenberger
chillenberger committedJan 20, 2024
commit771f841dd4a12160e2a7b77d03150ab5ef48fc6c
39 changes: 32 additions & 7 deletionspgml-dashboard/src/api/cms.rs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,6 +19,7 @@ use crate::{
utils::config,
};
use serde::{Deserialize, Serialize};
use std::fmt;

lazy_static! {
static ref BLOG: Collection = Collection::new(
Expand DownExpand Up@@ -62,13 +63,23 @@ lazy_static! {
);
}

#[derive(PartialEq,Debug, Serialize, Deserialize)]
#[derive(Debug, Serialize, Deserialize, Clone)]
pub enum DocType {
Blog,
Docs,
Careers,
}

impl fmt::Display for DocType {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
DocType::Blog => write!(f, "blog"),
DocType::Docs => write!(f, "docs"),
DocType::Careers => write!(f, "careers")
}
}
}

impl FromStr for DocType {
type Err = ();

Expand DownExpand Up@@ -97,12 +108,14 @@ pub struct Document {
pub toc_links: Vec<TocLink>,
pub contents: String,
pub doc_type: Option<DocType>,
// url to thumbnail for social share
pub thumbnail: Option<String>
}

// Gets document markdown
impl Document {
pub async fn from_path(path: &PathBuf) -> anyhow::Result<Document, std::io::Error> {
warn!("path: {:?}", path);
debug!("path: {:?}", path);

let regex = regex::Regex::new(r#".*/pgml-cms/([^"]*)/(.*)\.md"#).unwrap();

Expand DownExpand Up@@ -130,6 +143,8 @@ impl Document {
(None, contents)
};

let default_image = ".gitbook/assets/blog_image_placeholder.png";

// parse meta section
let (description, image, featured, tags) = match meta {
Some(meta) => {
Expand All@@ -140,9 +155,9 @@ impl Document {
};

let image = if meta["image"].is_badvalue() {
Some(".gitbook/assets/blog_image_placeholder.png".to_string())
Some(format!("/{}/{}", doc_type.clone().unwrap().to_string(), default_image))
} else {
Some(meta["image"].as_str().unwrap().to_string())
Some(format!("/{}/{}", doc_type.clone().unwrap().to_string().to_string(),meta["image"].as_str().unwrap()))
};

let featured = if meta["featured"].is_badvalue() {
Expand All@@ -165,12 +180,21 @@ impl Document {
}
None => (
None,
Some(".gitbook/assets/blog_image_placeholder.png".to_string()),
Some(format!("/{}/{}", doc_type.clone().unwrap().to_string(), default_image)),
false,
Vec::new(),
),
};

let thumbnail = match &image {
Some(image) => if image.contains(default_image) {
None
} else {
Some(format!("{}{}", config::site_domain(), image))
},
None => None
};

// Parse Markdown
let arena = Arena::new();
let root = parse_document(&arena, &contents, &crate::utils::markdown::options());
Expand All@@ -191,6 +215,7 @@ impl Document {
toc_links,
contents,
doc_type,
thumbnail
};
Ok(document)
}
Expand DownExpand Up@@ -419,8 +444,8 @@ impl Collection {
let index = self.open_index(&doc.path);

let mut layout = crate::templates::Layout::new(&doc.title, Some(cluster));
if let Some(image) = &doc.image {
layout.image(&config::asset_url(image.into()));
if let Some(image) = &doc.thumbnail {
layout.image(&image);
}
if let Some(description) = &doc.description {
layout.description(description);
Expand Down
31 changes: 14 additions & 17 deletionspgml-dashboard/src/components/layouts/head/template.html
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
<% use crate::utils::config; %>
<%
use crate::utils::config;

let thumbnail = image
.unwrap_or_else(|| format!(r#"{}/static/images/homepage-social-share.webp"#, config::site_domain()));

let description = description
.unwrap_or_else(|| String::from("Train and deploy models to make online predictions using only SQL, with an open source Postgres extension."));
%>

<head>
<meta charset="utf-8">
Expand All@@ -7,23 +15,12 @@
<meta name="author" content="PostgresML">
<title><%= title %> – PostgresML</title>

<% if description.is_some() { %>
<meta name="description" content="<%= description.clone().unwrap() %>">
<meta property="og:description" content="<%= description.clone().unwrap() %>">
<meta name="twitter:description" content="<%= description.clone().unwrap() %>">
<% } else { %>
<meta name="description" content="Train and deploy models to make online predictions using only SQL, with an open source Postgres extension.">
<meta property="og:description" content="Train and deploy models to make online predictions using only SQL, with an open source Postgres extension.">
<meta name="twitter:description" content="Train and deploy models to make online predictions using only SQL, with an open source Postgres extension.">
<% } %>
<meta name="description" content="<%- description %>">
<meta property="og:description" content="<%- description %>">
<meta name="twitter:description" content="<%- description %>">

<% if image.is_some() { %>
<meta property="og:image" content="<%= image.clone().unwrap() %>">
<meta name="twitter:image" content="<%= image.clone().unwrap() %>">
<% } else { %>
<meta property="og:image" content="https://postgresml.org/dashboard/static/images/owl_gradient.png">
<meta name="twitter:image" content="https://postgresml.org/dashboard/static/images/owl_gradient.png">
<% } %>
<meta property="og:image" content="<%- thumbnail %>">
<meta name="twitter:image" content="<%- thumbnail %>">

<meta property="og:site_name" content="PostgresML">
<meta property="og:type" content="website">
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -37,14 +37,12 @@ impl LandingPage {
.await
.unwrap();

let image = Some(format!("blog/{}", doc.image.unwrap()));

let meta = DocMeta {
description: doc.description,
author: doc.author,
author_image: doc.author_image,
date: doc.date,
image,
image: doc.image,
featured: doc.featured,
tags: doc.tags,
title: doc.title,
Expand Down
4 changes: 4 additions & 0 deletionspgml-dashboard/src/utils/config.rs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -145,6 +145,10 @@ pub fn asset_url(path: Cow<str>) -> String {
}
}

pub fn site_domain() -> String {
String::from("https://postgresml.org")
}

fn env_is_set(name: &str) -> bool {
var(name).is_ok()
}
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp