Unverified Commit a150b7aa authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

Optional decade / year / month headings

parent 36d33ba8
Loading
Loading
Loading
Loading
+27 −2
Original line number Diff line number Diff line
@@ -246,11 +246,12 @@ class ImageHTML:


class Thumbnail:
    def __init__(self, filename, im, size=250, with_gps=False):
    def __init__(self, filename, im, size=250, with_gps=False, group_key_template=None):
        self.filename = filename
        self.size = size
        self.exif_dt = None
        self.gps = None
        self.group_key = None

        with open(filename, "rb") as f:
            self.exif_tag = exifread.process_file(f)
@@ -288,6 +289,14 @@ class Thumbnail:
        self._get_makemodel()
        self._get_details()

        if group_key_template == "decade" and self.exif_dt:
            year = self.exif_dt.strftime("%Y")[:3]
            self.group_key = f"{year}0 – {year}9"
        elif group_key_template == "year" and self.exif_dt:
            self.group_key = self.exif_dt.strftime("%Y")
        elif group_key_template == "year-month" and self.exif_dt:
            self.group_key = self.exif_dt.strftime("%B %Y")

        if with_gps:
            self._get_gps()

@@ -562,6 +571,13 @@ if __name__ == "__main__":
        type=str,
        help="Set EXIF copyright (IN-PLACE EDIT)",
    )
    parser.add_argument(
        "--group",
        metavar="SEP",
        choices=["none", "year-month", "year", "decade"],
        default="none",
        help="Add captions to separate images by SEP",
    )
    parser.add_argument(
        "--html-include",
        metavar="FILE",
@@ -650,7 +666,11 @@ if __name__ == "__main__":
                continue

        thumbnail = Thumbnail(
            filename, im.copy(), size=args.size, with_gps=args.with_nominatim
            filename,
            im.copy(),
            size=args.size,
            with_gps=args.with_nominatim,
            group_key_template=args.group,
        )
        thumbnails.append(thumbnail)

@@ -701,7 +721,12 @@ if __name__ == "__main__":
    if args.sort == "time":
        thumbnails = sorted(thumbnails, key=lambda t: t.exif_dt, reverse=args.reverse)

    prev_heading = None

    for i, thumbnail in enumerate(thumbnails):
        if args.group and thumbnail.group_key != prev_heading:
            html_buf += f"<h1>{thumbnail.group_key}</h1>"
            prev_heading = thumbnail.group_key
        html_buf += thumbnail.to_html(i, args.with_detail_page)

    if args.with_detail_page:
+4 −0
Original line number Diff line number Diff line
@@ -7,6 +7,10 @@ a {
	color: #9999ff;
}

h1 {
	color: #cccccc;
}

.glightbox-clean
.gslide-description {
	color: #eeeeee!important;
+4 −0
Original line number Diff line number Diff line
@@ -2,6 +2,10 @@ a {
	color: #000099;
}

h1 {
	color: #333333;
}

.glightbox-mobile
.gslide-description {
	padding-top: 0!important;
+10 −0
Original line number Diff line number Diff line
@@ -6,6 +6,12 @@ a {
	text-decoration: none;
}

h1 {
	clear: both;
	padding-top: 1em;
	margin-left: 1em;
}

div.image-container {
	text-align: center;
	font-size: 80%;
@@ -14,6 +20,10 @@ div.image-container {
	height: /* $boxheight */;
}

div.image-list-end {
	clear: both;
}

div.image-container a {
	text-decoration: none;
}