Skip to content

Commit

Permalink
docs(core): cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jaysoo committed Apr 15, 2024
1 parent 9aeaf85 commit 74880b1
Show file tree
Hide file tree
Showing 29 changed files with 556 additions and 278 deletions.
35 changes: 35 additions & 0 deletions .eslintrc.base.json
@@ -0,0 +1,35 @@
{
"root": true,
"ignorePatterns": ["**/*"],
"plugins": ["@nx"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {
"@nx/enforce-module-boundaries": [
"error",
{
"enforceBuildableLibDependency": true,
"allow": [],
"depConstraints": [
{
"sourceTag": "*",
"onlyDependOnLibsWithTags": ["*"]
}
]
}
]
}
},
{
"files": ["*.ts", "*.tsx"],
"extends": ["plugin:@nx/typescript"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"extends": ["plugin:@nx/javascript"],
"rules": {}
}
]
}
@@ -1,16 +1,16 @@
---
title: 'Design Article 3'
title: 'Pinned post from 2019'
description: ''
authors:
- 'Juri Strumpflohner'
published: '2019-01-01'
updated: '2019-01-01'
- 'Zack DeRose'
cover_image: '/documentation/blog/images/thumbnail-nx15_7.png'
tags:
- design
- Nx
reposts:
- https://dev.to/nx/nx-conf-2023-recap-53ep
pinned: true
---

Bla bla some intro text.
Expand Down
@@ -1,11 +1,10 @@
---
title: 'Design Article 4'
title: 'Placeholder'
description: ''
authors:
- 'Juri Strumpflohner'
published: '2019-01-01'
updated: '2019-01-01'
cover_image: '/documentation/blog/images/thumbnail-own-trpc.png'
- 'Zack DeRose'
cover_image: '/documentation/blog/images/thumbnail-nx15_7.png'
tags:
- design
- Nx
Expand Down
24 changes: 24 additions & 0 deletions docs/blog/2020-02-01-placeholder.md
@@ -0,0 +1,24 @@
---
title: 'Placeholder'
description: ''
authors:
- 'Juri Strumpflohner'
cover_image: '/documentation/blog/images/thumbnail-nx15_7.png'
tags:
- design
- Nx
reposts:
- https://dev.to/nx/nx-conf-2023-recap-53ep
---

Bla bla some intro text.

## Code Example

```ts
const foo = 'bar';

function someFn() {
return foo;
}
```
24 changes: 24 additions & 0 deletions docs/blog/2022-02-01-placeholder.md
@@ -0,0 +1,24 @@
---
title: 'Placeholder'
description: ''
authors:
- 'Juri Strumpflohner'
cover_image: '/documentation/blog/images/thumbnail-nx15_7.png'
tags:
- design
- Nx
reposts:
- https://dev.to/nx/nx-conf-2023-recap-53ep
---

Bla bla some intro text.

## Code Example

```ts
const foo = 'bar';

function someFn() {
return foo;
}
```
@@ -1,17 +1,15 @@
---
title: 'Design Article 2x'
title: 'Nx Console Meets Nx Cloud'
description: ''
authors:
- 'Juri Strumpflohner'
published: '2019-01-01'
updated: '2019-01-01'
cover_image: '/documentation/blog/images/thumbnail-nx-console-nx-cloud.png'
slug: custom-slug
tags:
- design
- Nx
reposts:
- https://dev.to/nx/nx-conf-2023-recap-53ep
pinned: true
---

Bla bla some intro text.
Expand Down
24 changes: 24 additions & 0 deletions docs/blog/2023-03-01-placeholder.md
@@ -0,0 +1,24 @@
---
title: 'Placeholder'
description: ''
authors:
- 'Juri Strumpflohner'
cover_image: '/documentation/blog/images/thumbnail-nx15_7.png'
tags:
- design
- Nx
reposts:
- https://dev.to/nx/nx-conf-2023-recap-53ep
---

Bla bla some intro text.

## Code Example

```ts
const foo = 'bar';

function someFn() {
return foo;
}
```
24 changes: 24 additions & 0 deletions docs/blog/2023-04-01-placeholder.md
@@ -0,0 +1,24 @@
---
title: 'Post with a very long title that spans more than one line'
description: ''
authors:
- 'Juri Strumpflohner'
cover_image: '/documentation/blog/images/thumbnail-nx15_7.png'
tags:
- design
- Nx
reposts:
- https://dev.to/nx/nx-conf-2023-recap-53ep
---

Bla bla some intro text.

## Code Example

```ts
const foo = 'bar';

function someFn() {
return foo;
}
```
@@ -1,16 +1,15 @@
---
title: 'Design Article 5'
title: 'Build Your Own CLI'
description: ''
authors:
- 'Juri Strumpflohner'
published: '2019-01-01'
updated: '2019-01-01'
cover_image: '/documentation/blog/images/thumbnail-build-own-cli.png'
tags:
- design
- Nx
reposts:
- https://dev.to/nx/nx-conf-2023-recap-53ep
pinned: true
---

Bla bla some intro text.
Expand Down
Expand Up @@ -4,13 +4,14 @@ description: ''
authors:
- 'Juri Strumpflohner'
- 'Zack DeRose'
published: '2023-10-20'
date: '2023-10-20'
cover_image: '/documentation/blog/images/thumbnail-nx-conf-recap.png'
tags:
- design
- Nx
reposts:
- https://dev.to/nx/nx-conf-2023-recap-53ep
pinned: true
---

We're excited to announce the release of Nx version 17! In this article, we'll cover the main things you need to know to get the most of Nx 17!
Expand Down
102 changes: 51 additions & 51 deletions nx-dev/data-access-documents/src/lib/blog.api.ts
@@ -1,29 +1,8 @@
import { readFileSync, readdirSync } from 'fs';
import { join, basename } from 'path';
import { extractFrontmatter } from '@nx/nx-dev/ui-markdoc';

export type BlogPostFrontmatter = {
title: string;
description: string;
authors: string[];
published: string;
updated?: string;
cover_image: string;
tags: string[];
reposts: string[];
};

export type BlogPostDataEntry = {
content: string;
frontmatter: BlogPostFrontmatter;
filePath: string;
slug: string;
};

const calculateSlug = (filePath: string, frontmatter: any) => {
const baseName = basename(filePath, '.md');
return frontmatter.slug || baseName;
};
import { sortPosts } from './blog.util';
import { BlogPostDataEntry } from './blog.model';

export class BlogApi {
constructor(
Expand All @@ -41,38 +20,59 @@ export class BlogApi {
}

getBlogPosts(): BlogPostDataEntry[] {
const files = readdirSync(this.options.blogRoot);
const files: string[] = readdirSync(this.options.blogRoot);
const allPosts: BlogPostDataEntry[] = [];

for (const file of files) {
const filePath = join(this.options.blogRoot, file);
// filter out directories (e.g. images)
if (!filePath.endsWith('.md')) continue;

return files
.map((file) => {
const filePath = join(this.options.blogRoot, file);
const content = readFileSync(filePath, 'utf8');
const frontmatter = extractFrontmatter(content);
const slug = this.calculateSlug(filePath, frontmatter);
const post = {
content,
frontmatter: {
title: frontmatter.title,
description: frontmatter.description,
authors: frontmatter.authors,
date: this.calculateDate(file, frontmatter),
cover_image: frontmatter.cover_image ?? null,
tags: frontmatter.tags,
reposts: frontmatter.reposts,
pinned: frontmatter.pinned ?? false,
},
filePath,
slug,
};

// filter out directories (e.g. images etc)
if (!filePath.endsWith('.md')) {
return null;
}
if (!frontmatter.draft || process.env.NODE_ENV === 'development') {
allPosts.push(post);
}
}

const content = readFileSync(filePath, 'utf8');
return sortPosts(allPosts);
}

const frontmatter = extractFrontmatter(content);
const slug = calculateSlug(filePath, frontmatter);
private calculateSlug(filePath: string, frontmatter: any): string {
const baseName = basename(filePath, '.md');
return frontmatter.slug || baseName;
}

return {
content,
frontmatter: {
title: frontmatter.title,
description: frontmatter.description,
authors: frontmatter.authors,
published: frontmatter.published,
updated: frontmatter.updated ?? null,
cover_image: frontmatter.cover_image ?? null,
tags: frontmatter.tags,
reposts: frontmatter.reposts,
},
filePath,
slug,
};
})
.filter((x) => !!x);
private calculateDate(filename: string, frontmatter: any): string {
const date: Date = new Date();
const timeString = date.toTimeString();
if (frontmatter.date) {
return new Date(frontmatter.date + ' ' + timeString).toISOString();
} else {
const regexp = /^(\d\d\d\d-\d\d-\d\d).+$/;
const match = filename.match(regexp);
if (match) {
return new Date(match[1] + ' ' + timeString).toISOString();
} else {
throw new Error(`Could not parse date from filename: ${filename}`);
}
}
}
}
18 changes: 18 additions & 0 deletions nx-dev/data-access-documents/src/lib/blog.model.ts
@@ -0,0 +1,18 @@
export type BlogPostFrontmatter = {
title: string;
description: string;
authors: string[];
date: string;
updated?: string;
cover_image: string;
tags: string[];
reposts: string[];
pinned?: boolean;
};

export type BlogPostDataEntry = {
content: string;
frontmatter: BlogPostFrontmatter;
filePath: string;
slug: string;
};

0 comments on commit 74880b1

Please sign in to comment.