Skip to content

Commit

Permalink
Merge pull request #31 from curvenote/feat/arxiv
Browse files Browse the repository at this point in the history
Add arxiv to frontmatter
  • Loading branch information
Yxwww authored May 20, 2022
2 parents ace30b4 + 15a30f6 commit 1edfbab
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 15 deletions.
5 changes: 5 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,10 @@ module.exports = {
moduleNameMapper: {
'src/(.*)': '<rootDir>/src/$1',
},
globals: {
'ts-jest': {
tsConfig: 'tsconfig.test.json',
},
},
setupFilesAfterEnv: ['./test.setup.ts'],
};
31 changes: 18 additions & 13 deletions src/blocks/types/frontMatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,36 @@ import { Author } from './author';

// All frontmatter props are optional in order to save storage and transfer payload size
// When the values are null indicates it has been explicitly set to null.
export interface BlockFrontMatterProps {
authors?: Author[] | null;
licenses?: { content: string | null; code: string | null } | null;
doi?: string | null;
open_access?: boolean | null;
github?: string | null;
binder?: string | null;
subtitle?: string | null;
short_title?: string | null;
venue?: { title?: string; url?: string } | null;
biblio?: {

export type FrontMatterProps = {
authors: Author[] | null;
licenses: { content: string | null; code: string | null } | null;
doi: string | null;
arxiv: string | null;
open_access: boolean | null;
github: string | null;
binder: string | null;
subtitle: string | null;
short_title: string | null;
venue: { title?: string; url?: string } | null;
biblio: {
volume?: string;
issue?: string;
first_page?: string;
last_page?: string;
} | null;
}
};

export type BlockFrontMatterProps = Partial<FrontMatterProps>;

export type ProjectFrontMatterProps = Omit<BlockFrontMatterProps, 'venue' | 'biblio'>;

// TODO: ensure exhausiveness
// Exhausiveness is ensured in test
export const PROJECT_FRONT_MATTER_KEYS = [
'authors',
'licenses',
'doi',
'arxiv',
'open_access',
'github',
'binder',
Expand Down
24 changes: 22 additions & 2 deletions src/blocks/utils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BlockFrontMatterProps, ProjectFrontMatterProps } from './types';
import { BlockFrontMatterProps, FrontMatterProps, ProjectFrontMatterProps } from './types';
import { extractBlockFrontMatter, extractProjectFrontMatter } from './utils';

export const TEST_PROJECT_FRONT_MATTER: ProjectFrontMatterProps = {
Expand All @@ -19,7 +19,7 @@ export const TEST_BLOCK_FRONT_MATTER: BlockFrontMatterProps = {
};

const TEST_FRONT_MATTER_OBJ = {
authors: [{ test: 'test' }],
authors: [],
license: undefined, // handles undefined
github: null,
short_title: '',
Expand All @@ -30,6 +30,26 @@ const TEST_FRONT_MATTER_OBJ = {
};

describe('extractBlockFrontMatter', () => {
test('should handle correct frontmatter extraction exhausively', () => {
const frontmatter: FrontMatterProps = {
authors: [],
licenses: { content: 'MIT', code: null },
github: null,
doi: 'doi',
arxiv: 'arxiv',
binder: 'binder',
subtitle: 'subtitle',
short_title: '',
open_access: false,
venue: {},
biblio: {},
};

expect(extractBlockFrontMatter(frontmatter)).toEqual(frontmatter);
const { venue, biblio, ...projectExtractionResult } = frontmatter;
expect(extractProjectFrontMatter(frontmatter)).toEqual(projectExtractionResult);
});

test('should extract block front matter properly', () => {
const target = { ...TEST_FRONT_MATTER_OBJ };

Expand Down
4 changes: 4 additions & 0 deletions tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "./tsconfig.json",
"exclude": []
}

0 comments on commit 1edfbab

Please sign in to comment.