Skip to content

Commit

Permalink
chore(remark): clean up typings
Browse files Browse the repository at this point in the history
  • Loading branch information
angrybacon committed May 19, 2024
1 parent d46d21c commit c426be4
Show file tree
Hide file tree
Showing 11 changed files with 17 additions and 22 deletions.
1 change: 1 addition & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export default [
{ argsIgnorePattern: '^_', ignoreRestSiblings: true },
],
'import/consistent-type-specifier-style': ['error', 'prefer-inline'],
'no-console': ['error', { allow: ['error', 'warn'] }],
},
},
].map((it) => ({
Expand Down
2 changes: 1 addition & 1 deletion src/components/Markdown/renderers/Decklist.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const Decklist: FunctionComponent<Props> = ({ decklist, node }) => {
mainCount={decklist.mainCount}
side={decklist.side[0] || []}
sideCount={decklist.sideCount}
title={decklist.title || decklist.titleAsFile}
title={decklist.title || decklist.titleFromPath}
/>
);
};
4 changes: 2 additions & 2 deletions src/tools/decklists/getDecklists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ export const getDecklists = (): Decklists => {
const decklist = parse(readFileSync(path, 'utf8'));
const [title, ...dateCrumbs] = crumbs.reverse();
const date: null | string = formatDate(...dateCrumbs.reverse());
const titleAsFile = title as string;
return { ...accumulator, [slug]: { ...decklist, date, titleAsFile } };
const titleFromPath = title as string;
return { ...accumulator, [slug]: { ...decklist, date, titleFromPath } };
}, {});
return decklists;
};
2 changes: 1 addition & 1 deletion src/tools/decklists/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export type Decklist = {

export type DecklistExtra = {
date: null | string;
titleAsFile: string;
titleFromPath: string;
};

export type Decklists = Record<string, Decklist & DecklistExtra>;
2 changes: 1 addition & 1 deletion src/tools/markdown/getMarkdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ import {
type Chapter,
type Partial,
} from '@/tools/markdown/types';
import { remarkMatter } from '@/tools/remark/remarkFrontmatter.server';
import { remarkMana } from '@/tools/remark/remarkMana.server';
import { remarkMinutes } from '@/tools/remark/remarkMinutes.server';
import { remarkScries } from '@/tools/remark/remarkScries.server';
import { type Scries } from '@/tools/scryfall/types';
import { remarkMatter } from '../remark/remarkFrontmatter.server';

/**
* Read the Markdown content found at the provided path crumbs.
Expand Down
5 changes: 2 additions & 3 deletions src/tools/remark/remarkBase.client.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { hastify } from '@korumite/kiwi/client';
import { type Directives } from 'mdast-util-directive';
import { type Node } from 'unist';
import { visit, type Test } from 'unist-util-visit';
import { visit } from 'unist-util-visit';

import { type Remarker } from '@/tools/remark/typings';

/** Preliminary visit to mark directives by name for future remarkers. */
export const remarkBase: Remarker = () => (tree) => {
const tests = ['containerDirective', 'leafDirective', 'textDirective'];
visit<Node, Test>(tree, tests, (node) => {
visit(tree, tests, (node) => {
const directive = node as Directives;
hastify(directive, directive.attributes || {});
});
Expand Down
5 changes: 2 additions & 3 deletions src/tools/remark/remarkCard.client.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import { hastify } from '@korumite/kiwi/client';
import { type Text } from 'mdast';
import { type TextDirective } from 'mdast-util-directive';
import { type Node } from 'unist';
import { select } from 'unist-util-select';
import { visit, type Test } from 'unist-util-visit';
import { visit } from 'unist-util-visit';

import { getCard } from '@/tools/game/getCard';
import { type Remarker } from '@/tools/remark/typings';

/** Augment card directives with the real cards names. */
export const remarkCard: Remarker = () => (tree) => {
const tests = [{ name: 'card', type: 'textDirective' }];
visit<Node, Test>(tree, tests, (node) => {
visit(tree, tests, (node) => {
const directive = node as TextDirective;
const text = select('text', directive) as Text | undefined;
if (text) {
Expand Down
5 changes: 2 additions & 3 deletions src/tools/remark/remarkDecklist.client.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { hastify } from '@korumite/kiwi/client';
import { type LeafDirective } from 'mdast-util-directive';
import { type Node } from 'unist';
import { visit, type Test } from 'unist-util-visit';
import { visit } from 'unist-util-visit';

import { type Decklists } from '@/tools/decklists/types';
import { type Remarker } from '@/tools/remark/typings';
Expand All @@ -11,7 +10,7 @@ export const remarkDecklist: Remarker<[{ decklists: Decklists }]> =
({ decklists }) =>
(tree) => {
const tests = [{ name: 'decklist', type: 'leafDirective' }];
visit<Node, Test>(tree, tests, (node) => {
visit(tree, tests, (node) => {
const directive = node as LeafDirective;
const path = directive.attributes?.path;
if (path) {
Expand Down
3 changes: 1 addition & 2 deletions src/tools/remark/remarkMinutes.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@ export const remarkMinutes: Plugin = () => async (tree, file) => {
text += (node as Literal).value;
});
const { minutes } = readingTime(text);
console.log(minutes);
file.data.minutes = Math.ceil(minutes);
Object.assign(file.data, { minutes });
};
5 changes: 2 additions & 3 deletions src/tools/remark/remarkRow.client.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { hastify } from '@korumite/kiwi/client';
import { type Text } from 'mdast';
import { type ContainerDirective } from 'mdast-util-directive';
import { type Node } from 'unist';
import { select } from 'unist-util-select';
import { visit, type Test } from 'unist-util-visit';
import { visit } from 'unist-util-visit';

import { type Remarker } from '@/tools/remark/typings';
import { type Scries } from '@/tools/scryfall/types';
Expand All @@ -13,7 +12,7 @@ export const remarkRow: Remarker<[{ scries: Scries }]> =
({ scries }) =>
(tree) => {
const tests = [{ name: 'row', type: 'containerDirective' }];
visit<Node, Test>(tree, tests, (node) => {
visit(tree, tests, (node) => {
const directive = node as ContainerDirective;
const text = select('text', directive) as Text | undefined;
if (text) {
Expand Down
5 changes: 2 additions & 3 deletions src/tools/remark/remarkScries.server.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { type Text } from 'mdast';
import { type ContainerDirective } from 'mdast-util-directive';
import { type Plugin } from 'unified';
import { type Node } from 'unist';
import { select } from 'unist-util-select';
import { visit, type Test } from 'unist-util-visit';
import { visit } from 'unist-util-visit';

import { readFaces } from '@/tools/scryfall/read';
import { scry } from '@/tools/scryfall/scry';
Expand All @@ -17,7 +16,7 @@ export const remarkScries: Plugin = () => async (tree, file) => {
const promises: Promise<ScryData>[] = [];
const scries: Scries = {};
const tests = [{ name: 'row', type: 'containerDirective' }];
visit<Node, Test>(tree, tests, (node) => {
visit(tree, tests, (node) => {
const directive = node as ContainerDirective;
const text = select('text', directive) as Text | undefined;
if (!text) {
Expand Down

0 comments on commit c426be4

Please sign in to comment.