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