Skip to content

Commit

Permalink
feat: relocate data loaders
Browse files Browse the repository at this point in the history
  • Loading branch information
tada5hi committed Nov 26, 2024
1 parent 4ae1439 commit effc063
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 18 deletions.
11 changes: 5 additions & 6 deletions src/.vitepress/components/person/KPerson.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
-->

<script lang="ts">
import {computed, defineComponent} from "vue";
import {Person} from '../../domains';
import { computed, defineComponent } from "vue";
import { Person } from '../../domains';
import { KHistoryEntries } from "../history";

import { data } from '../team/team.data';
import { data } from '../../data/team.data';
import KPersonContact from "../utilities/contact/KContactDetails.vue";

export default defineComponent({
Expand All @@ -21,10 +21,9 @@ export default defineComponent({
}
},
setup(props) {
const persons : [string, Person][] = data;
const entity = computed<Person>(() => {
const index = persons.findIndex((member) => member[0] === props.slug);
return persons[index][1];
const index = data.findIndex((member) => member[0] === props.slug);
return data[index][1];
});

return {
Expand Down
2 changes: 1 addition & 1 deletion src/.vitepress/components/publication/KPublications.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { VCPagination } from '@vuecs/pagination';
import { parse } from '@retorquere/bibtex-parser';
import { computed, defineComponent, ref } from 'vue';
import { VPTeamPageTitle } from 'vitepress/theme';
import { data } from './bib.data';
import { data } from '../../data/bib.data';
import KPublication from './KPublication.vue';

export default defineComponent({
Expand Down
2 changes: 1 addition & 1 deletion src/.vitepress/components/team/KTeam.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import { TeamID } from '../../domains/team/constants';
import KTeamMembers from "./KTeamMembers.vue";
import KTeamSwitch from './KTeamSwitch.vue';
import {data} from "./team.data";
import {data} from "../../data/team.data";

export default defineComponent({
components: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
/*
* Copyright (c) 2024.
* Copyright (c) 2024-2024.
* Author Peter Placzek (tada5hi)
* For the full copyright and license information,
* view the LICENSE file that was distributed with this source code.
*/

import fs from 'fs';
import path from "node:path";

declare const data: string;
export { data };

export default {
async load() {
return fs.promises.readFile('src/.vitepress/data/publications/pub.bib', { encoding: 'utf8' });
return fs.promises.readFile(
path.join(import.meta.dirname, './publications/pub.bib'),
{ encoding: 'utf8' }
);
},
};
2 changes: 1 addition & 1 deletion src/.vitepress/data/persons/placzek-peter.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default definePerson({
],
education: [
{
year: [2002, 2006],
year: [2002, 2008],
value: 'Grundschule Pliezhausen'
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
/*
* Copyright (c) 2024.
* Copyright (c) 2024-2024.
* Author Peter Placzek (tada5hi)
* For the full copyright and license information,
* view the LICENSE file that was distributed with this source code.
*/

import {Person, readPersons} from "../../domains";
import {Person, readPersons} from "../domains";

declare const data: [string, Person][];
export { data };

export default {
async load() {
return readPersons();
watch: ['./persons/*.mjs'],
async load(files: string[]) {
return readPersons(files);
},
};
10 changes: 8 additions & 2 deletions src/.vitepress/domains/person/read.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,14 @@ import path from "node:path";
import {PERSON_DIRECTORY} from "../../constants";
import { Person } from "./types";

export async function readPersons() : Promise<[string, Person][]> {
const files = await fs.promises.readdir(PERSON_DIRECTORY);
export async function readPersons(input?: string[]) : Promise<[string, Person][]> {
let files: string[] = [];
if (input) {
files = input.map((el) => path.basename(el));
} else {
files = await fs.promises.readdir(PERSON_DIRECTORY);
}

const members : [string, Person][] = [];
for(let i=0; i<files.length; i++) {
const slug = files[i].replace(/\.[^/.]+$/, "");
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"lib": [
"ESNext"
],
"module": "commonjs",
"module": "ESNext",
"outDir": "dist",
"target": "ESNext",
"experimentalDecorators": true,
Expand Down

0 comments on commit effc063

Please sign in to comment.