Skip to content

Commit

Permalink
Removed obsolete functions
Browse files Browse the repository at this point in the history
  • Loading branch information
deanmoses committed Jan 3, 2023
1 parent de79279 commit 7f18c72
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 38 deletions.
17 changes: 0 additions & 17 deletions src/lib/models/impl/album-impl.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { Album, Image, AlbumNavInfo, AlbumThumb } from '$lib/models/album';
import { ImageImpl } from '$lib/models/impl/image-impl';
import { processCaption } from '$lib/utils/legacyUrlHandler';
import { getYearFromPath } from '$lib/utils/path-utils';

/**
* Album implementation
Expand Down Expand Up @@ -31,22 +30,6 @@ export class AlbumImpl implements Album {
return processCaption(this.desc);
}

/**
* Get year the album was published, like 2001
*/
get year(): number {
// First look at the path: this lets us get the right color for the "Loading..." page
// before we have the publication date
const year = getYearFromPath(this.path);
if (year) {
return year;
} else {
// Else look at the publication date
// Default to 1900 if no publication date, I guess
return new Date((this.date ?? 1900) * 1000).getFullYear();
}
}

/**
* Friendly title of page
* Blank if no title
Expand Down
25 changes: 4 additions & 21 deletions src/lib/utils/path-utils.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,7 @@
import { AlbumType } from '$lib/models/album';

const dateBasedPathRegex = /^\/?(\d\d\d\d)\/?(\d\d-\d\d)?(\/[^\/\.]+\.[^\/\.]{3,4})?\/?$/; // finds 2000 or 2000/12-31 or 2000/12-31/someImage.jpg
const yearRegex = /^\/?(\d\d\d\d)\/?$/;

/**
* Return the year (like 2001) from a path (like 2001/12-31/myImage.jpg)
*
* @param path Path to an image or an album
* @return numerical year or null if the path can't be parsed into a number
*/
export function getYearFromPath(path: string): number {
const regexResults = dateBasedPathRegex.exec(path);
if (regexResults) {
const year = Number(dateBasedPathRegex.exec(path)[1]);
return !isNaN(year) ? year : null;
} else {
return null;
}
}

/**
* Return the parent path from the given path. For example:
* - If the path is an image, it returns the album the image is in.
Expand All @@ -39,9 +22,9 @@ export function getParentFromPath(path: string): string {
* - If the path is an image like 2001/12-31/photo.jpg, it returns photo.jpg
* - If the path is an album like 2001/12-31, it returns 12-31
* - If the path is 2001, it returns 2001
* - If the path is empty, it return empty
* - If the path is empty, it returns undefined
*/
export function getLeafItemOnPath(path: string): string {
export function getLeafItemOnPath(path: string): string | undefined {
return path.split('/').pop(); // we just want 'felix.jpg'
}

Expand Down Expand Up @@ -106,6 +89,6 @@ export function editUrl(path: string | undefined): string | undefined {
* @param path path in edit mode, like /edit/2001/12-31
* @returns the non-edit version of the URL, like /2001/12-31
*/
export function unEditUrl(path: string): string {
return path.replace(/^\/edit/, '');
export function unEditUrl(path: string | undefined): string | undefined {
return path?.replace(/^\/edit/, '') ?? undefined;
}

0 comments on commit 7f18c72

Please sign in to comment.