Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pagination buttons #36

Merged
merged 4 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 4 additions & 4 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ jobs:

- uses: Swatinem/rust-cache@v2
- name: Build
run: npm i && npx tailwindcss -i ./input.css -o ./out/output.css && RUST_BACKTRACE=1 cargo run --release
run: npm i && npx tailwindcss -i ./input.css -o ./out/blog/output.css && RUST_BACKTRACE=1 cargo run --release
- name: Generate Previews
run: |
cd preview_generator
cargo run --release -- blog ../articles ../out/articles
cargo run --release -- this_week ../esta_semana_en_rust/ ../out/articles/
cargo run --release -- blog ../articles ../out/blog/articles
cargo run --release -- this_week ../esta_semana_en_rust/ ../out/blog/articles
- name: Upload artifact
uses: actions/upload-pages-artifact@v1
with:
name: out
path: ./out
path: ./out/blog

deploy:
environment:
Expand Down
2 changes: 1 addition & 1 deletion src/components/blog_content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ pub fn ArticleHeader(
class="p-1 m-1 border-2 rounded-full
text-sm font-bold text-orange-500 hover:text-orange-600 bg-white drop-shadow-sm
"
href=format!("/tag/{}", tag)
href=format!("/blog/tags/{}.html", tag)
>
{tag}
</a>
Expand Down
2 changes: 1 addition & 1 deletion src/components/card_article.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub fn TagButton(tag: String) -> impl IntoView {
<li class="inline-block text-sm font-bold text-orange-500 hover:text-orange-600">
<a
class="inline-block bg-white rounded-md p-1 drop-shadow-sm px-2"
href=format!("./tags/{}.html", tag)
href=format!("/blog/tags/{}.html", tag)
>
{tag}
</a>
Expand Down
33 changes: 16 additions & 17 deletions src/components/pagination_buttons.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
use crate::components::icons::StrToIcon;
use leptos::{component, view, IntoAttribute, IntoView};
use leptos::{component, view, IntoAttribute, IntoView, Show};

#[component]
pub fn PaginationButtons(
hide: bool,
current_page: Option<usize>,
max_page: usize,
) -> impl IntoView {
let page_number = current_page.unwrap_or(0);

let show_next_page_button = page_number < max_page || max_page == 0;
let show_prev_page_button = page_number > 0;

view! {
<>

{if hide {
view! { <></> }
} else {
let page_number = current_page.unwrap_or(0);
let hide_next_page_button = page_number >= max_page && max_page != 0;
view! {
<>
<PreviousPageButton page=current_page/>
<NextPageButton page=current_page hide=hide_next_page_button/>
<Show when=move || show_prev_page_button fallback=|| ()>
<PreviousPageButton page=current_page/>
</Show>
<Show when=move || show_next_page_button fallback=|| ()>
<NextPageButton page=current_page/>
</Show>
</>
}
}}
Expand All @@ -30,14 +37,10 @@ pub fn PaginationButtons(
pub fn PreviousPageButton(page: Option<usize>) -> impl IntoView {
let page = page.unwrap_or(0);

if page == 0 {
return view! { <></> };
}

let previous_page = if page == 1 {
"/".to_string()
"/blog".to_string()
} else {
format!("/pages/{}.html", page - 1)
format!("/blog/pages/{}.html", page - 1)
};

view! {
Expand All @@ -54,13 +57,9 @@ pub fn PreviousPageButton(page: Option<usize>) -> impl IntoView {
}

#[component]
pub fn NextPageButton(page: Option<usize>, hide: bool) -> impl IntoView {
if hide {
return view! { <></> };
}

pub fn NextPageButton(page: Option<usize>) -> impl IntoView {
let page = page.unwrap_or(0);
let link = format!("/pages/{}.html", page + 1);
let link = format!("/blog/pages/{}.html", page + 1);

view! {
<>
Expand Down
14 changes: 7 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ pub static ARTICLES: Lazy<RwLock<Vec<Article>>> =
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let articles = list_articles().await?;
ARTICLES.write().await.extend(articles.clone()); // Set the articles in the ARTICLES static variable
let out = Path::new("./out");
let out = Path::new("./out/blog");
if !out.exists() {
std::fs::create_dir(out).expect("Cannot create 'out' directory");
std::fs::create_dir_all(out).expect("Cannot create 'out' directory");
}
let ssg = Ssg::new(out);

Expand Down Expand Up @@ -78,7 +78,7 @@ async fn generate_esta_semana_en_rust<'a>(

generate_feed_rss(
&articles,
"./out/this_week_feed.xml",
"./out/blog/this_week_feed.xml",
"Esta Semana en Rust",
"Revisa que esta pasando en la comunidad de Rust Lang en Español",
Some("tags/esta-semana-en-rust.html"),
Expand All @@ -98,7 +98,7 @@ async fn generate_post_pages<'a>(
articles: Vec<Article>,
ssg: &Ssg<'a>,
) -> Result<(), Box<dyn std::error::Error>> {
tokio::fs::create_dir_all("./out/articles").await?;
tokio::fs::create_dir_all("./out/blog/articles").await?;

{
let articles = articles
Expand All @@ -109,7 +109,7 @@ async fn generate_post_pages<'a>(

generate_feed_rss(
&articles,
"./out/feed.xml",
"./out/blog/feed.xml",
"Blog de RustLangES",
"Enterate del mejor contenido en Español sobre Rust",
None,
Expand Down Expand Up @@ -142,7 +142,7 @@ async fn generate_tag_pages<'a>(
.flatten()
.collect::<Vec<String>>();

tokio::fs::create_dir_all("./out/tags").await?;
tokio::fs::create_dir_all("./out/blog/tags").await?;

for tag in tags {
let articles_to_show = articles
Expand Down Expand Up @@ -240,7 +240,7 @@ async fn generate_pages<'a>(
mut articles: Vec<Article>,
ssg: &Ssg<'a>,
) -> Result<(), Box<dyn std::error::Error>> {
tokio::fs::create_dir_all("./out/pages").await?;
tokio::fs::create_dir_all("./out/blog/pages").await?;

if let Some(last_this_week_in_rust) = articles.iter().position(|a| a.number_of_week.is_some()) {
articles.remove(last_this_week_in_rust);
Expand Down
Loading