Skip to content

Commit

Permalink
ui improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
zaknesler committed May 31, 2024
1 parent 51d9f5c commit 5b2c086
Show file tree
Hide file tree
Showing 22 changed files with 373 additions and 325 deletions.
46 changes: 23 additions & 23 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/blend-feed/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ reqwest = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
thiserror = { workspace = true }
tracing = { workspace = true }
url = { workspace = true }
30 changes: 0 additions & 30 deletions crates/blend-feed/src/extract/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,3 @@ mod text;
pub use html::*;
pub use stylistic::*;
pub use text::*;

/// Test if given input is likely HTML, based on the difference between the parsed style/inline tags vs. the sanitized HTML.
pub fn likely_html(src: &str) -> bool {
let stylistic = extract_stylistic_html(src, "");
let html = extract_html(src, "");

stylistic != html
}

#[cfg(test)]
mod test {
use super::*;

#[test]
fn returns_true_for_html() {
assert_eq!(likely_html(r#"<p>Some HTML</p>"#), true);
assert_eq!(likely_html(r#"<div>Some HTML</div>"#), true);
assert_eq!(likely_html(r#"<div>Some <em>HTML</em></div>"#), true);
}

#[test]
fn returns_false_for_non_html() {
assert_eq!(likely_html(r#"Some HTML"#), false);
assert_eq!(likely_html(r#"Some <em>HTML</em>"#), false);
assert_eq!(
likely_html(r#"<strike><strong>Some</strong> <em>HTML</em></strike>"#),
false
);
}
}
2 changes: 1 addition & 1 deletion crates/blend-feed/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ mod model;
mod parse;
mod readability;
mod scrape;
mod util;
pub(crate) mod util;

pub use error::FeedError as Error;
pub use extract::*;
Expand Down
8 changes: 4 additions & 4 deletions crates/blend-feed/src/parse/entry.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::{get_feed, parse_url};
use crate::{error::FeedResult, extract::*, ParsedEntry};
use crate::{error::FeedResult, extract::*, util::*, ParsedEntry};

/// Number of characters after which we can just assume the summary is the content, without needing to guess that it's HTML
const MAX_SUMMARY_LENGTH: usize = 1000;
Expand Down Expand Up @@ -43,9 +43,9 @@ pub async fn parse_entries(url: &str) -> FeedResult<Vec<ParsedEntry>> {

// Some feeds may return article content as the summary/teaser, so if it's likely HTML, let's swap these fields
if content_html.is_none()
&& summary_html
.as_ref()
.is_some_and(|value| value.len() >= MAX_SUMMARY_LENGTH || likely_html(value))
&& entry.summary.as_ref().is_some_and(|text| {
text.content.len() >= MAX_SUMMARY_LENGTH || likely_html(&text.content)
})
{
content_html = entry.summary.map(|text| extract_html(&text.content, base_url));
summary_html = None;
Expand Down
48 changes: 48 additions & 0 deletions crates/blend-feed/src/util/likely_html.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
use crate::{extract_html, extract_stylistic_html};

/// Test if given input is likely HTML, based on the difference between the parsed style/inline tags vs. the sanitized HTML.
pub fn likely_html(src: &str) -> bool {
let stylistic = extract_stylistic_html(src, "");
let html = extract_html(src, "");

stylistic != html
}

#[cfg(test)]
mod test {
use super::*;

#[test]
fn returns_true_for_html() {
assert_eq!(likely_html(r#"<p>Some HTML</p>"#), true);
assert_eq!(likely_html(r#"<div>Some HTML</div>"#), true);
assert_eq!(likely_html(r#"<div>Some <em>HTML</em></div>"#), true);
}

#[test]
fn returns_false_for_non_html() {
assert_eq!(likely_html(r#"Some HTML"#), false);
assert_eq!(likely_html(r#"Some <em>HTML</em>"#), false);
assert_eq!(
likely_html(r#"<strike><strong>Some</strong> <em>HTML</em></strike>"#),
false
);
}

#[test]
fn it_works_on_real_example() {
let src = r#"
<p class="feature-image">
<a href="https://example.com">
<img width="1600" height="840" src="https://example.com/image.jpg" class="attachment-card-large size-card-large wp-post-image" alt="Some image." decoding="async" />
</a>
</p>
<p>Some long description.</p>
<p class="read-more">
[<a href="https://example.com">Read More</a>]
</p>
"#;

assert_eq!(likely_html(src), true);
}
}
5 changes: 5 additions & 0 deletions crates/blend-feed/src/util/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mod likely_html;
mod request;

pub use likely_html::*;
pub use request::*;
File renamed without changes.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
"typeshare:generate": "typeshare ./ --lang typescript --output-file ./ui/src/types/bindings.ts && biome check --apply ./ui/src/types/bindings.ts"
},
"dependencies": {
"@kobalte/core": "^0.13.1",
"@kobalte/core": "^0.13.2",
"@kobalte/tailwindcss": "^0.9.0",
"@solid-primitives/active-element": "^2.0.20",
"@solid-primitives/bounds": "^0.0.121",
"@solid-primitives/keyboard": "^1.2.8",
"@solid-primitives/resize-observer": "^2.0.25",
"@solid-primitives/scheduled": "^1.4.3",
"@solid-primitives/scroll": "^2.0.23",
"@solidjs/router": "^0.13.3",
"@solidjs/router": "^0.13.4",
"@tanstack/solid-query": "^5.40.0",
"@tanstack/solid-query-devtools": "^5.40.0",
"class-variance-authority": "^0.7.0",
Expand All @@ -34,7 +34,7 @@
},
"devDependencies": {
"@biomejs/biome": "1.7.3",
"@swc/core": "^1.5.7",
"@swc/core": "^1.5.24",
"@swc/jest": "^0.2.36",
"@tailwindcss/forms": "^0.5.7",
"@tailwindcss/typography": "^0.5.13",
Expand All @@ -46,7 +46,7 @@
"solid-devtools": "^0.30.1",
"tailwindcss": "^3.4.3",
"typescript": "^5.4.5",
"vite": "^5.2.11",
"vite": "^5.2.12",
"vite-plugin-solid": "^2.10.2",
"vite-tsconfig-paths": "^4.3.2"
},
Expand Down
Loading

0 comments on commit 5b2c086

Please sign in to comment.