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

Commit744209c

Browse files
update deeplink (#1304)
1 parent1061c9f commit744209c

File tree

6 files changed

+52
-84
lines changed

6 files changed

+52
-84
lines changed

‎pgml-dashboard/src/api/cms.rs‎

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -116,19 +116,15 @@ pub struct Document {
116116
implDocument{
117117
pubasyncfnfrom_path(path:&PathBuf) -> anyhow::Result<Document, std::io::Error>{
118118
let doc_type =match path.strip_prefix(config::cms_dir()){
119-
Ok(path) =>{
120-
match path.into_iter().next(){
121-
Some(dir) =>{
122-
match&PathBuf::from(dir).display().to_string()[..]{
123-
"blog" =>Some(DocType::Blog),
124-
"docs" =>Some(DocType::Docs),
125-
"careers" =>Some(DocType::Careers),
126-
_ =>None
127-
}
128-
},
129-
_ =>None
130-
}
131-
},
119+
Ok(path) =>match path.into_iter().next(){
120+
Some(dir) =>match&PathBuf::from(dir).display().to_string()[..]{
121+
"blog" =>Some(DocType::Blog),
122+
"docs" =>Some(DocType::Docs),
123+
"careers" =>Some(DocType::Careers),
124+
_ =>None,
125+
},
126+
_ =>None,
127+
},
132128
_ =>None,
133129
};
134130

@@ -155,7 +151,11 @@ impl Document {
155151
(None, contents)
156152
};
157153

158-
let default_image_path =BLOG.asset_url_root.join("blog_image_placeholder.png").display().to_string();
154+
let default_image_path =BLOG
155+
.asset_url_root
156+
.join("blog_image_placeholder.png")
157+
.display()
158+
.to_string();
159159

160160
// parse meta section
161161
let(description, image, featured, tags) =match meta{
@@ -171,16 +171,14 @@ impl Document {
171171
Some(default_image_path.clone())
172172
}else{
173173
matchPathBuf::from_str(meta["image"].as_str().unwrap()){
174-
Ok(image_path) =>{
175-
match image_path.file_name(){
176-
Some(file_name) =>{
177-
let file =PathBuf::from(file_name).display().to_string();
178-
Some(BLOG.asset_url_root.join(file).display().to_string())
179-
},
180-
_ =>Some(default_image_path.clone())
174+
Ok(image_path) =>match image_path.file_name(){
175+
Some(file_name) =>{
176+
let file =PathBuf::from(file_name).display().to_string();
177+
Some(BLOG.asset_url_root.join(file).display().to_string())
181178
}
179+
_ =>Some(default_image_path.clone()),
182180
},
183-
_ =>Some(default_image_path.clone())
181+
_ =>Some(default_image_path.clone()),
184182
}
185183
};
186184

@@ -202,12 +200,7 @@ impl Document {
202200

203201
(description, image, featured, tags)
204202
}
205-
None =>(
206-
None,
207-
Some(default_image_path.clone()),
208-
false,
209-
Vec::new(),
210-
),
203+
None =>(None,Some(default_image_path.clone()),false,Vec::new()),
211204
};
212205

213206
let thumbnail =match&image{
@@ -287,7 +280,7 @@ pub struct Collection {
287280
/// A list of old paths to new paths in this collection
288281
redirects:HashMap<&'staticstr,&'staticstr>,
289282
/// Url to assets for this collection
290-
pubasset_url_root:PathBuf
283+
pubasset_url_root:PathBuf,
291284
}
292285

293286
implCollection{
@@ -455,7 +448,7 @@ impl Collection {
455448
if path.has_root(){
456449
path = path.strip_prefix("/").unwrap().to_owned();
457450
}
458-
451+
459452
letmut path_v = path.components().collect::<Vec<_>>();
460453
path_v.remove(0);
461454

@@ -870,7 +863,7 @@ This is the end of the markdown
870863
)
871864
}
872865

873-
// Test we can parse doc meta with out issue.
866+
// Test we can parse doc meta with out issue.
874867
#[sqlx::test]
875868
asyncfndocs_meta_parse(){
876869
let collection =&crate::api::cms::DOCS;
@@ -883,7 +876,7 @@ This is the end of the markdown
883876
}
884877
}
885878

886-
// Test we can parse blog meta with out issue.
879+
// Test we can parse blog meta with out issue.
887880
#[sqlx::test]
888881
asyncfnblog_meta_parse(){
889882
let collection =&crate::api::cms::BLOG;
@@ -896,7 +889,7 @@ This is the end of the markdown
896889
}
897890
}
898891

899-
// Test we can parse career meta with out issue.
892+
// Test we can parse career meta with out issue.
900893
#[sqlx::test]
901894
asyncfncareer_meta_parse(){
902895
let collection =&crate::api::cms::CAREERS;

‎pgml-dashboard/src/components/pages/blog/landing_page/mod.rs‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ impl LandingPage {
3030
for urlin urls{
3131
let file = collection.url_to_path(url.as_ref());
3232

33-
let doc =crate::api::cms::Document::from_path(&file)
34-
.await
35-
.unwrap();
33+
let doc =crate::api::cms::Document::from_path(&file).await.unwrap();
3634

3735
let meta =DocMeta{
3836
description: doc.description,

‎pgml-dashboard/src/templates/docs.rs‎

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
use convert_case;
2-
use lazy_static::lazy_static;
32
use sailfish::TemplateOnce;
43
use serde::{Deserialize,Serialize};
5-
use std::collections::hash_map::DefaultHasher;
6-
use std::hash::{Hash,Hasher};
74

85
usecrate::utils::markdown::SearchResult;
96

@@ -15,26 +12,6 @@ pub struct Search {
1512
pubresults:Vec<SearchResult>,
1613
}
1714

18-
lazy_static!{
19-
static refCMS_IDENTIFIER:CmsIdentifier =CmsIdentifier::new();
20-
}
21-
22-
// Prevent css collisions in cms header ids.
23-
pubstructCmsIdentifier{
24-
pubid:String,
25-
}
26-
27-
implCmsIdentifier{
28-
pubfnnew() ->CmsIdentifier{
29-
letmut s =DefaultHasher::new();
30-
"cms header".hash(&mut s);
31-
32-
CmsIdentifier{
33-
id: s.finish().to_string(),
34-
}
35-
}
36-
}
37-
3815
/// Table of contents link.
3916
#[derive(Clone,Debug,Serialize,Deserialize)]
4017
pubstructTocLink{
@@ -57,14 +34,12 @@ impl TocLink {
5734

5835
// gitbook style id's
5936
let id =format!(
60-
"{}{}-{}",
61-
id,
37+
"{id}{}",
6238
if counter >0{
6339
format!("-{counter}")
6440
} else{
6541
String::new()
66-
},
67-
CMS_IDENTIFIER.id
42+
}
6843
);
6944

7045
TocLink{
@@ -92,7 +67,7 @@ impl TocLink {
9267
},
9368
_ =>TocLink{
9469
title: link.clone(),
95-
id:format!("#{}-{}", link.clone(),CMS_IDENTIFIER.id),
70+
id:format!("{}", link.clone()),
9671
level:0,
9772
},
9873
}

‎pgml-dashboard/src/utils/config.rs‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,11 @@ pub fn asset_url(path: Cow<str>) -> String {
146146
}
147147

148148
pubfnsite_domain() ->String{
149-
String::from("https://postgresml.org")
149+
ifCONFIG.dev_mode{
150+
String::from("https://localhost")
151+
}else{
152+
String::from("https://postgresml.org")
153+
}
150154
}
151155

152156
fnenv_is_set(name:&str) ->bool{

‎pgml-dashboard/src/utils/markdown.rs‎

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use tantivy::query::{QueryParser, RegexQuery};
2020
use tantivy::schema::*;
2121
use tantivy::tokenizer::{LowerCaser,NgramTokenizer,TextAnalyzer};
2222
use tantivy::{Index,IndexReader,SnippetGenerator};
23+
use url::Url;
2324

2425
use std::sync::Mutex;
2526

@@ -795,11 +796,18 @@ pub fn mkdocs<'a>(root: &'a AstNode<'a>, arena: &'a Arena<AstNode<'a>>) -> anyho
795796

796797
iter_nodes(root,&mut |node|{
797798
match&mut node.data.borrow_mut().value{
798-
// Strip .md extensions that gitbook includes in page link urls
799+
// Strip .md extensions that gitbook includes in page link urls.
799800
&mutNodeValue::Link(refmut link) =>{
800801
let path =Path::new(link.url.as_str());
801-
802-
if path.is_relative(){
802+
let url =Url::parse(link.url.as_str());
803+
804+
// Ignore absolute urls that are not site domain, github has .md endpoints
805+
if url.is_err()
806+
|| url?.host_str().unwrap_or_else(||"")
807+
==Url::parse(&config::site_domain())?
808+
.host_str()
809+
.unwrap_or_else(||"postgresml.org")
810+
{
803811
let fragment =match link.url.find("#"){
804812
Some(index) => link.url[index +1..link.url.len()].to_string(),
805813
_ =>"".to_string(),
@@ -822,10 +830,13 @@ pub fn mkdocs<'a>(root: &'a AstNode<'a>, arena: &'a Arena<AstNode<'a>>) -> anyho
822830
}
823831
}
824832

825-
//Add fragment paththat matches toc links.
833+
//Reappend the pathfragment.
826834
let header_id =TocLink::from_fragment(fragment).id;
827-
for cin header_id.chars(){
828-
link.url.push(c)
835+
if header_id.len() >0{
836+
link.url.push('#');
837+
for cin header_id.chars(){
838+
link.url.push(c)
839+
}
829840
}
830841
}
831842

‎pgml-dashboard/static/js/docs-toc.js‎

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,6 @@ import {
33
}from'@hotwired/stimulus';
44

55
exportdefaultclassextendsController{
6-
connect(){
7-
this.scrollSpyAppend();
8-
}
9-
10-
scrollSpyAppend(){
11-
constspy=newbootstrap.ScrollSpy(document.body,{
12-
target:'#toc-nav',
13-
smoothScroll:true,
14-
rootMargin:'-10% 0% -50% 0%',
15-
threshold:[1],
16-
})
17-
}
18-
196
setUrlFragment(e){
207
lethref=e.target.attributes.href.nodeValue;
218
if(href){

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp