Skip to content

Commit

Permalink
feat: use image named like the folder as cover
Browse files Browse the repository at this point in the history
  • Loading branch information
herteleo committed Oct 25, 2022
1 parent 6bf7b61 commit eee008e
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 22 deletions.
14 changes: 0 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
"highlight.js": "^11.4.0",
"iconoir": "^1.0.0",
"marked": "^4.0.12",
"slugify": "^1.6.5",
"vue": "^3.2.41",
"vue-router": "^4.1.5"
},
Expand Down
2 changes: 1 addition & 1 deletion src/components/DirEntry.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const getDirPreview = async () => {
const entries = await setupDirEntries(props.entry.handle);
const coverEntry = getDirCoverEntry(entries, props.entry.handle.name);
const coverEntry = getDirCoverEntry(entries, props.entry.displayName);
if (coverEntry?.isFile) return setFileAsImage(coverEntry.file);
const firstImage = getFirstImageEntry(entries);
Expand Down
6 changes: 1 addition & 5 deletions src/features/useDir.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { computed, nextTick, onMounted, ref, watch } from 'vue';
import { onBeforeRouteUpdate, useRoute, useRouter } from 'vue-router';
import slugify from 'slugify';
import { getTagsFromString, removeTagsFromString } from '@/features/useDirFilter';

interface CurrentDirEntryBase {
Expand Down Expand Up @@ -53,11 +52,8 @@ export const getDirCoverEntry = (
entries: CurrentDirEntry[],
dirName: string
): CurrentDirEntry | undefined => {
const dirNameSlugged = slugify(dirName, { lower: true });

const cover = entries.find(
(e) =>
e.type === 'image' && e.file.name.toLowerCase().replace(/\.[^/.]+$/, '') === dirNameSlugged
(e) => e.type === 'image' && e.displayName.replace(/\.[^/.]+$/, '') === dirName
);
if (cover) return cover;
};
Expand Down
2 changes: 1 addition & 1 deletion src/views/Dir.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ watch(readmeEntry, async (entry) => {
});
const dirThumbEntry = computed(() =>
getDirCoverEntry(currentDirEntries.value, currentDir.value?.name || '')
getDirCoverEntry(currentDirEntries.value, removeTagsFromString(currentDir.value?.name || ''))
);
const dirThumbSrc = computed(
() => dirThumbEntry.value?.isFile && URL.createObjectURL(dirThumbEntry.value.file)
Expand Down

0 comments on commit eee008e

Please sign in to comment.