use regex for matching github repo urls
This commit is contained in:
parent
134cba4061
commit
cae88a20ff
@ -1,11 +1,11 @@
|
|||||||
use scraper::{Html, Selector};
|
use scraper::{Html, Selector};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
use crate::engines::{Response, CLIENT};
|
use crate::engines::{answer::regex, Response, CLIENT};
|
||||||
|
|
||||||
pub fn request(response: &Response) -> Option<reqwest::RequestBuilder> {
|
pub fn request(response: &Response) -> Option<reqwest::RequestBuilder> {
|
||||||
for search_result in response.search_results.iter().take(8) {
|
for search_result in response.search_results.iter().take(8) {
|
||||||
if search_result.url.starts_with("https://github.com/") {
|
if regex!(r"^https:\/\/github\.com\/[\w-]+\/[\w.-]+$").is_match(&search_result.url) {
|
||||||
return Some(CLIENT.get(search_result.url.as_str()));
|
return Some(CLIENT.get(search_result.url.as_str()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -43,6 +43,8 @@ pub fn parse_response(body: &str) -> Option<String> {
|
|||||||
|
|
||||||
let mut readme_html = ammonia::Builder::default()
|
let mut readme_html = ammonia::Builder::default()
|
||||||
.link_rel(None)
|
.link_rel(None)
|
||||||
|
.add_allowed_classes("div", &["markdown-alert"])
|
||||||
|
.add_allowed_classes("p", &["markdown-alert-title"])
|
||||||
.url_relative(ammonia::UrlRelative::RewriteWithBase(
|
.url_relative(ammonia::UrlRelative::RewriteWithBase(
|
||||||
Url::parse("https://github.com").unwrap(),
|
Url::parse("https://github.com").unwrap(),
|
||||||
))
|
))
|
||||||
|
@ -268,6 +268,13 @@ h1 {
|
|||||||
font-weight: normal;
|
font-weight: normal;
|
||||||
font-size: 0.8em;
|
font-size: 0.8em;
|
||||||
}
|
}
|
||||||
|
.infobox-github-readme .markdown-alert {
|
||||||
|
padding-left: 0.5em;
|
||||||
|
border-left: 0.25em solid #234;
|
||||||
|
}
|
||||||
|
.infobox-github-readme .markdown-alert-title {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
.postsearch-infobox p {
|
.postsearch-infobox p {
|
||||||
margin-bottom: 1em;
|
margin-bottom: 1em;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user