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 docs 2#1252

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 2 commits intomasterfromdan-docs-2
Dec 21, 2023
Merged
Changes fromall commits
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
76 changes: 53 additions & 23 deletionspgml-dashboard/src/api/cms.rs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,12 +3,7 @@ use std::path::{Path, PathBuf};
use comrak::{format_html_with_plugins, parse_document, Arena, ComrakPlugins};
use lazy_static::lazy_static;
use markdown::mdast::Node;
use rocket::{
fs::NamedFile,
http::{uri::Origin, Status},
route::Route,
State,
};
use rocket::{fs::NamedFile, http::uri::Origin, route::Route, State};
use yaml_rust::YamlLoader;

use crate::{
Expand DownExpand Up@@ -39,11 +34,19 @@ pub struct Document {
}

impl Document {
pub fn new(content: &str) -> Document {
Document {
path: PathBuf::new(),
description: None,
image: None,
title: "404".to_string(),
toc_links: Vec::new(),
html: content.to_string(),
}
}

pub async fn from_path(path: &PathBuf) -> anyhow::Result<Document, std::io::Error> {
let contents = match tokio::fs::read_to_string(&path).await {
Ok(contents) => contents,
Err(_) => String::from("<h3>Failed to find your requested document!</h3>"),
};
let contents = tokio::fs::read_to_string(&path).await?;

let parts = contents.split("---").collect::<Vec<&str>>();

Expand DownExpand Up@@ -156,7 +159,7 @@ impl Collection {
mut path: PathBuf,
cluster: &Cluster,
origin: &Origin<'_>,
) -> Result<ResponseOk,Status> {
) -> Result<ResponseOk,crate::responses::NotFound> {
info!("get_content: {} | {path:?}", self.name);

if origin.path().ends_with("/") {
Expand DownExpand Up@@ -273,17 +276,21 @@ impl Collection {
}

// renders document in layout
async fn render<'a>(&self, path: &'a PathBuf, cluster: &Cluster) -> Result<ResponseOk, Status> {
async fn render<'a>(
&self,
path: &'a PathBuf,
cluster: &Cluster,
) -> Result<ResponseOk, crate::responses::NotFound> {
let user = if cluster.context.user.is_anonymous() {
None
} else {
Some(cluster.context.user.clone())
};

match Document::from_path(&path).await {
Ok(doc) => {
let index = self.open_index(doc.path);

let user = if cluster.context.user.is_anonymous() {
None
} else {
Some(cluster.context.user.clone())
};

let mut layout = crate::templates::Layout::new(&doc.title, Some(cluster));
if let Some(image) = doc.image {
layout.image(&config::asset_url(image.into()));
Expand All@@ -306,7 +313,30 @@ impl Collection {
))
}
// Return page not found on bad path
_ => Err(Status::NotFound),
_ => {
let mut layout = crate::templates::Layout::new("404", None);

let doc = crate::api::cms::Document::new(
r#"
<div style='height: 80vh'>
<h2>Oops, document not found!</h2>
<p>The document you are searching for may have been moved or replaced with better content.</p>
</div>"#,
);

if let Some(user) = &user {
layout.user(user);
}

layout
.nav_links(&self.index)
.nav_title(&self.name)
.footer(cluster.context.marketing_footer.to_string());

layout.render(crate::templates::Article { content: doc.html });

Err(crate::responses::NotFound(layout.into()))
}
}
}
}
Expand DownExpand Up@@ -344,7 +374,7 @@ async fn get_blog(
path: PathBuf,
cluster: &Cluster,
origin: &Origin<'_>,
) -> Result<ResponseOk,Status> {
) -> Result<ResponseOk,crate::responses::NotFound> {
BLOG.get_content(path, cluster, origin).await
}

Expand All@@ -353,7 +383,7 @@ async fn get_careers(
path: PathBuf,
cluster: &Cluster,
origin: &Origin<'_>,
) -> Result<ResponseOk,Status> {
) -> Result<ResponseOk,crate::responses::NotFound> {
CAREERS.get_content(path, cluster, origin).await
}

Expand All@@ -362,7 +392,7 @@ async fn get_docs(
path: PathBuf,
cluster: &Cluster,
origin: &Origin<'_>,
) -> Result<ResponseOk,Status> {
) -> Result<ResponseOk,crate::responses::NotFound> {
DOCS.get_content(path, cluster, origin).await
}

Expand DownExpand Up@@ -550,7 +580,7 @@ This is the end of the markdown
let rsp = req.dispatch().await;

assert!(
rsp.status() == Status::Ok,
rsp.status() == Status::NotFound,
"Returned status {:?}",
rsp.status()
);
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp