Skip to content

Commit

Permalink
Fix loading JSON files when running with npx globally.
Browse files Browse the repository at this point in the history
  • Loading branch information
evert committed Dec 6, 2024
1 parent 552fd17 commit 9c3dc47
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Changelog
------------------

* Add CSS style for experimental feature
* Fix an issue with loading JSON files when running as a dependency via npx.


1.1.1 (2024-02-01)
Expand Down
11 changes: 10 additions & 1 deletion src/components/links-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,21 @@ import * as React from 'react';
import { Link } from 'ketting';
import { PageProps } from '../types.js';
import { readFileSync } from 'node:fs';
import { fileURLToPath } from 'node:url';
import * as path from 'node:path';

type LinkDescriptions = Record<string, {href: string; description: string}>;

function loadLinkData(fileName: string) {
return JSON.parse(
readFileSync(new URL(import.meta.url + '/..').pathname + '../../data/' + fileName + '.json', 'utf-8')
readFileSync(
path.join(
fileURLToPath(new URL(import.meta.url + '/..')),
'../../data/',
fileName + '.json'
),
'utf-8'
)
);
}

Expand Down

0 comments on commit 9c3dc47

Please sign in to comment.