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 blog search#1359

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 10 commits intomasterfromdan-blog-search
Mar 6, 2024
Merged
Show file tree
Hide file tree
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
97 changes: 88 additions & 9 deletionspgml-dashboard/src/api/cms.rs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,6 +21,9 @@ use crate::{
use serde::{Deserialize, Serialize};
use std::fmt;

use crate::components::cards::blog::article_preview;
use sailfish::TemplateOnce;

lazy_static! {
pub static ref BLOG: Collection = Collection::new(
"Blog",
Expand DownExpand Up@@ -120,6 +123,25 @@ impl Document {
Document { ..Default::default() }
}

// make a document from a uri of form <blog || docs || careers>/< path and file name >
pub async fn from_url(url: &str) -> anyhow::Result<Document, std::io::Error> {
let doc_type = match url.split('/').collect::<Vec<&str>>().get(1) {
Some(&"blog") => Some(DocType::Blog),
Some(&"docs") => Some(DocType::Docs),
Some(&"careers") => Some(DocType::Careers),
_ => None,
};

let path = match doc_type {
Some(DocType::Blog) => BLOG.url_to_path(url),
Some(DocType::Docs) => DOCS.url_to_path(url),
Some(DocType::Careers) => CAREERS.url_to_path(url),
_ => PathBuf::new(),
};

Document::from_path(&path).await
}

pub async fn from_path(path: &PathBuf) -> anyhow::Result<Document, std::io::Error> {
let doc_type = match path.strip_prefix(config::cms_dir()) {
Ok(path) => match path.into_iter().next() {
Expand DownExpand Up@@ -673,6 +695,49 @@ async fn search(query: &str, site_search: &State<crate::utils::markdown::SiteSea
)
}

#[get("/search_blog?<query>&<tag>", rank = 20)]
async fn search_blog(query: &str, tag: &str, site_search: &State<crate::utils::markdown::SiteSearch>) -> ResponseOk {
let tag = if tag.len() > 0 {
Some(Vec::from([tag.to_string()]))
} else {
None
};

// If user is not making a search return all blogs in default design.
let results = if query.len() > 0 || tag.clone().is_some() {
let results = site_search.search(query, Some(DocType::Blog), tag.clone()).await;

let results = match results {
Ok(results) => results
.into_iter()
.map(|document| article_preview::DocMeta::from_document(document))
.collect::<Vec<article_preview::DocMeta>>(),
Err(_) => Vec::new(),
};

results
} else {
let mut results = Vec::new();

for url in BLOG.get_all_urls() {
let doc = Document::from_url(&url).await.unwrap();

results.push(article_preview::DocMeta::from_document(doc));
}

results
};

let is_search = query.len() > 0 || tag.is_some();

ResponseOk(
crate::components::pages::blog::blog_search::Response::new()
.pattern(results, is_search)
.render_once()
.unwrap(),
)
}

#[get("/blog/.gitbook/assets/<path>", rank = 10)]
pub async fn get_blog_asset(path: &str) -> Option<NamedFile> {
BLOG.get_asset(path).await
Expand DownExpand Up@@ -751,13 +816,25 @@ async fn blog_landing_page(cluster: &Cluster) -> Result<ResponseOk, crate::respo
.theme(Theme::Docs)
.footer(cluster.context.marketing_footer.to_string());

Ok(ResponseOk(
layout.render(
crate::components::pages::blog::LandingPage::new(cluster)
.index(&BLOG)
.await,
),
))
let mut index = Vec::new();

let urls = BLOG.get_all_urls();

for url in urls {
let doc = Document::from_url(&url).await.unwrap();
let meta = article_preview::DocMeta::from_document(doc);
index.push(meta)
}

let featured_cards = index
.clone()
.into_iter()
.filter(|x| x.featured)
.collect::<Vec<article_preview::DocMeta>>();

Ok(ResponseOk(layout.render(
crate::components::pages::blog::LandingPage::new(cluster).featured_cards(featured_cards),
)))
}

#[get("/docs")]
Expand DownExpand Up@@ -806,7 +883,8 @@ pub fn routes() -> Vec<Route> {
get_docs,
get_docs_asset,
get_user_guides,
search
search,
search_blog
]
}

Expand DownExpand Up@@ -880,8 +958,9 @@ This is the end of the markdown

async fn rocket() -> Rocket<Build> {
dotenv::dotenv().ok();

rocket::build()
// .manage(crate::utils::markdown::SearchIndex::open().unwrap())
// .manage(crate::utils::markdown::SiteSearch::new().await.expect("Error initializing site search"))
.mount("/", crate::api::cms::routes())
}

Expand Down
View file
Open in desktop

This file was deleted.

29 changes: 17 additions & 12 deletionspgml-dashboard/src/components/cards/blog/article_preview/mod.rs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,6 +17,22 @@ pub struct DocMeta {
pub path: String,
}

impl DocMeta {
pub fn from_document(doc: Document) -> DocMeta {
DocMeta {
description: doc.description,
author: doc.author,
author_image: doc.author_image,
featured: doc.featured,
date: doc.date,
tags: doc.tags,
image: doc.image,
title: doc.title,
path: doc.url,
}
}
}

#[derive(TemplateOnce)]
#[template(path = "cards/blog/article_preview/template.html")]
pub struct ArticlePreview {
Expand DownExpand Up@@ -59,18 +75,7 @@ impl ArticlePreview {

pub async fn from_path(path: &str) -> ArticlePreview {
let doc = Document::from_path(&PathBuf::from(path)).await.unwrap();

let meta = DocMeta {
description: doc.description,
author: doc.author,
author_image: doc.author_image,
featured: false,
date: doc.date,
tags: doc.tags,
image: doc.image,
title: doc.title,
path: doc.url,
};
let meta = DocMeta::from_document(doc);
ArticlePreview::new(&meta)
}
}
Expand Down
37 changes: 37 additions & 0 deletionspgml-dashboard/src/components/loading/dots/dots.scss
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
div {
@mixin loading-dot($delay, $initial) {
width: 30px;
height: 30px;
opacity: $initial;
border-radius: 30px;
background-color: #{$gray-100};
animation: opacity 3s infinite linear;
animation-delay: $delay;
}

.loading-dot-1 {
@include loading-dot(0s, 0.1);
}

.loading-dot-2 {
@include loading-dot(0.5s, 0.2);
}

.loading-dot-3 {
@include loading-dot(1s, 0.3);
}

@keyframes opacity {
0% {
opacity: 0.1;
}

75% {
opacity: 1;
}

100% {
opacity: 0.1;
}
}
}
14 changes: 14 additions & 0 deletionspgml-dashboard/src/components/loading/dots/mod.rs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
use pgml_components::component;
use sailfish::TemplateOnce;

#[derive(TemplateOnce, Default)]
#[template(path = "loading/dots/template.html")]
pub struct Dots {}

impl Dots {
pub fn new() -> Dots {
Dots {}
}
}

component!(Dots);
8 changes: 8 additions & 0 deletionspgml-dashboard/src/components/loading/dots/template.html
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
<div class="d-flex flex-row gap-3">
<div class="loading-dot-1">
</div>
<div class="loading-dot-2">
</div>
<div class="loading-dot-3">
</div>
</div>
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
div[data-controller="loading-message"] {}
23 changes: 23 additions & 0 deletionspgml-dashboard/src/components/loading/message/mod.rs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
use sailfish::TemplateOnce;
use pgml_components::component;

#[derive(TemplateOnce, Default)]
#[template(path = "loading/message/template.html")]
pub struct Message {
message: String,
}

impl Message {
pub fn new() -> Message {
Message {
message: String::from("Loading..."),
}
}

pub fn message(mut self, message: &str) -> Message {
self.message = String::from(message);
self
}
}

component!(Message);
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
<% use crate::components::loading::Dots; %>
<div class="d-flex flex-column justify-content-center align-items-center w-100 gap-3">
<%+ Dots::new() %>
<h6 class="fw-semibold"><%- message %></h6>
</div>
10 changes: 10 additions & 0 deletionspgml-dashboard/src/components/loading/mod.rs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
// This file is automatically generated.
// You shouldn't modify it manually.

// src/components/loading/dots
pub mod dots;
pub use dots::Dots;

// src/components/loading/message
pub mod message;
pub use message::Message;
3 changes: 3 additions & 0 deletionspgml-dashboard/src/components/mod.rs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -52,6 +52,9 @@ pub use left_nav_menu::LeftNavMenu;
// src/components/lists
pub mod lists;

// src/components/loading
pub mod loading;

// src/components/modal
pub mod modal;
pub use modal::Modal;
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -42,7 +42,7 @@

<div class="d-flex flex-row gap-1">
<li class="nav-item d-flex align-items-center d-block d-xl-none">
<button type="text" class="btn nav-link btn-search-alt border-0 p-0" name="search" data-bs-toggle="modal" data-bs-target="#search" autocomplete="off" data-search-target="searchTrigger" data-action="search#openSearch">
<button type="text" class="btn nav-link btn-search-input-webapp border-0 p-0" name="search" data-bs-toggle="modal" data-bs-target="#search" autocomplete="off" data-search-target="searchTrigger" data-action="search#openSearch">
<span class="material-symbols-outlined">search</span>
</button>
</li>
Expand DownExpand Up@@ -88,7 +88,7 @@
<% } %>

<li class="nav-item d-none d-xl-flex align-items-center">
<button type="text" class="btn nav-link btn-search-alt border-0 p-0" name="search" data-bs-toggle="modal" data-bs-target="#search" autocomplete="off" data-search-target="searchTrigger" data-action="search#openSearch">
<button type="text" class="btn nav-link btn-search-input-webapp border-0 p-0" name="search" data-bs-toggle="modal" data-bs-target="#search" autocomplete="off" data-search-target="searchTrigger" data-action="search#openSearch">
<span class="material-symbols-outlined">search</span>
</button>
</li>
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
div[data-controller="pages-blog-blog-search-call"] {
.btn-primary {
@include media-breakpoint-down(md) {
padding: 12px 16px;
}
}

.btn-tag {
border: 2px solid #{$gray-200};
background-color: transparent;
color: #{$gray-200};

&.selected{
background-color: #{$gray-100};
border-color: #{$gray-100};
color: #{$gray-900};
}

&:hover:not(.all-tags), &:hover:not(.selected):is(.all-tags) {
background-color: transparent;
color: #{$gray-100};
border-color: #{$gray-100};
@include bold_by_shadow(var(#{$gray-100}));
}

&:active:not(.all-tags), &:active:not(.selected):is(.all-tags){
background-color: #{$gray-200};
border-color: #{$gray-200};
color: #{$gray-900};
}
}
}
Loading

[8]ページ先頭

©2009-2025 Movatter.jp