github fixes and responsive search bar
This commit is contained in:
parent
60914e6e7f
commit
03d74ddac8
@ -19,15 +19,16 @@ pub fn request(response: &Response) -> Option<reqwest::RequestBuilder> {
|
|||||||
pub fn parse_response(body: &str) -> Option<String> {
|
pub fn parse_response(body: &str) -> Option<String> {
|
||||||
let dom = Html::parse_document(body);
|
let dom = Html::parse_document(body);
|
||||||
|
|
||||||
let url = Url::join(
|
let url_relative = dom
|
||||||
&Url::parse("https://github.com").unwrap(),
|
.select(
|
||||||
dom.select(&Selector::parse("main #repository-container-header a").unwrap())
|
&Selector::parse("main #repository-container-header strong[itemprop='name'] > a")
|
||||||
.next()?
|
.unwrap(),
|
||||||
.value()
|
)
|
||||||
.attr("href")?,
|
.next()?
|
||||||
)
|
.value()
|
||||||
.ok()?
|
.attr("href")?;
|
||||||
.to_string();
|
let url = format!("https://github.com{url_relative}");
|
||||||
|
|
||||||
let readme = dom.select(&Selector::parse("article").unwrap()).next()?;
|
let readme = dom.select(&Selector::parse("article").unwrap()).next()?;
|
||||||
let readme_html = readme.inner_html().trim().to_string();
|
let readme_html = readme.inner_html().trim().to_string();
|
||||||
|
|
||||||
@ -40,12 +41,21 @@ pub fn parse_response(body: &str) -> Option<String> {
|
|||||||
.to_string();
|
.to_string();
|
||||||
|
|
||||||
let readme_dom = Html::parse_fragment(&readme_html);
|
let readme_dom = Html::parse_fragment(&readme_html);
|
||||||
let title_el = readme_dom.select(&Selector::parse("h1").unwrap()).next()?;
|
let title = if let Some(title_el) = readme_dom.select(&Selector::parse("h1").unwrap()).next() {
|
||||||
let title_html = title_el.html().trim().to_string();
|
let title_html = title_el.html().trim().to_string();
|
||||||
if readme_html.starts_with(&title_html) {
|
if readme_html.starts_with(&title_html) {
|
||||||
readme_html = readme_html[title_html.len()..].to_string();
|
readme_html = readme_html[title_html.len()..].to_string();
|
||||||
}
|
}
|
||||||
let title = title_el.text().collect::<String>();
|
title_el.text().collect::<String>()
|
||||||
|
} else {
|
||||||
|
dom.select(
|
||||||
|
&Selector::parse("main #repository-container-header strong[itemprop='name'] > a")
|
||||||
|
.unwrap(),
|
||||||
|
)
|
||||||
|
.next()?
|
||||||
|
.text()
|
||||||
|
.collect::<String>()
|
||||||
|
};
|
||||||
|
|
||||||
Some(format!(
|
Some(format!(
|
||||||
r#"<a href="{url}"><h1>{title}</h1></a>
|
r#"<a href="{url}"><h1>{title}</h1></a>
|
||||||
|
@ -65,9 +65,12 @@ h1 {
|
|||||||
/* header */
|
/* header */
|
||||||
.search-form {
|
.search-form {
|
||||||
margin-bottom: 1rem;
|
margin-bottom: 1rem;
|
||||||
|
display: flex;
|
||||||
|
gap: 0.5rem;
|
||||||
}
|
}
|
||||||
#search-input {
|
#search-input {
|
||||||
width: 20em;
|
max-width: 30em;
|
||||||
|
flex: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* search result */
|
/* search result */
|
||||||
|
Loading…
Reference in New Issue
Block a user