Cleanup.
This commit is contained in:
parent
63fac99f27
commit
8e7a3a36b6
@ -512,28 +512,28 @@ fn person_one<'mw>(
|
|||||||
.order(date.desc().nulls_last())
|
.order(date.desc().nulls_last())
|
||||||
.load::<Photo>(c)
|
.load::<Photo>(c)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
if photos.len() < 42 {
|
if let Some(groups) = split_to_groups(&photos) {
|
||||||
return res.ok(|o| {
|
|
||||||
templates::person(
|
|
||||||
o,
|
|
||||||
req,
|
|
||||||
&photos.iter().map(PhotoLink::from).collect::<Vec<_>>(),
|
|
||||||
&person,
|
|
||||||
)
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
return res.ok(|o| {
|
return res.ok(|o| {
|
||||||
let path = req.path_without_query().unwrap_or("/");
|
let path = req.path_without_query().unwrap_or("/");
|
||||||
templates::person(
|
templates::person(
|
||||||
o,
|
o,
|
||||||
req,
|
req,
|
||||||
&split_to_groups(&photos)
|
&groups
|
||||||
.iter()
|
.iter()
|
||||||
.map(|g| PhotoLink::for_group(g, path))
|
.map(|g| PhotoLink::for_group(g, path))
|
||||||
.collect::<Vec<_>>(),
|
.collect::<Vec<_>>(),
|
||||||
&person,
|
&person,
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
return res.ok(|o| {
|
||||||
|
templates::person(
|
||||||
|
o,
|
||||||
|
req,
|
||||||
|
&photos.iter().map(PhotoLink::from).collect::<Vec<_>>(),
|
||||||
|
&person,
|
||||||
|
)
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
res.not_found("Not a person")
|
res.not_found("Not a person")
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
use models::Photo;
|
use models::Photo;
|
||||||
|
|
||||||
pub fn split_to_groups(photos: &[Photo]) -> Vec<&[Photo]> {
|
pub fn split_to_groups(photos: &[Photo]) -> Option<Vec<&[Photo]>> {
|
||||||
|
if photos.len() < 42 {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
let wanted_groups = (photos.len() as f64).sqrt() as usize;
|
let wanted_groups = (photos.len() as f64).sqrt() as usize;
|
||||||
let mut groups = vec![&photos[..]];
|
let mut groups = vec![&photos[..]];
|
||||||
while groups.len() < wanted_groups {
|
while groups.len() < wanted_groups {
|
||||||
@ -9,7 +12,7 @@ pub fn split_to_groups(photos: &[Photo]) -> Vec<&[Photo]> {
|
|||||||
groups[i] = a;
|
groups[i] = a;
|
||||||
groups.insert(i + 1, b);
|
groups.insert(i + 1, b);
|
||||||
}
|
}
|
||||||
groups
|
Some(groups)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn find_largest(groups: &[&[Photo]]) -> usize {
|
fn find_largest(groups: &[&[Photo]]) -> usize {
|
||||||
|
@ -3,5 +3,5 @@
|
|||||||
@(photo: &PhotoLink)
|
@(photo: &PhotoLink)
|
||||||
<p class="item">
|
<p class="item">
|
||||||
<a href="@photo.href"><img src="/img/@photo.id-s.jpg"></a>
|
<a href="@photo.href"><img src="/img/@photo.id-s.jpg"></a>
|
||||||
@if let &Some(ref d) = &photo.lable {<br/>@d}
|
@if let Some(ref d) = photo.lable {<br/>@d}
|
||||||
</p>
|
</p>
|
||||||
|
Loading…
Reference in New Issue
Block a user