Skip to content

Commit 68bd5ac

Browse files
feat(blog): pages
1 parent 2719146 commit 68bd5ac

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+1374
-0
lines changed

apps/blog-bff/src/main.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { HTTPException } from 'hono/http-exception';
55
import { articles } from '@angular-love/blog-bff/articles/api';
66
import { authors } from '@angular-love/blog-bff/authors/api';
77
import { newsletter } from '@angular-love/blog-bff/newsletter/api';
8+
import { pages } from '@angular-love/blog-bff/pages/api';
89

910
const app = new Hono();
1011

@@ -13,6 +14,7 @@ app.use('*', cors());
1314
app.route('/articles', articles);
1415
app.route('/authors', authors);
1516
app.route('/newsletter', newsletter);
17+
app.route('/pages', pages);
1618

1719
app.onError((err, c) => {
1820
console.error(err);
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"extends": ["../../../../.eslintrc.json"],
3+
"ignorePatterns": ["!**/*"],
4+
"overrides": [
5+
{
6+
"files": ["*.ts"],
7+
"extends": [
8+
"plugin:@nx/angular",
9+
"plugin:@angular-eslint/template/process-inline-templates"
10+
],
11+
"rules": {
12+
"@angular-eslint/directive-selector": [
13+
"error",
14+
{
15+
"type": "attribute",
16+
"prefix": "al",
17+
"style": "camelCase"
18+
}
19+
],
20+
"@angular-eslint/component-selector": [
21+
"error",
22+
{
23+
"type": "element",
24+
"prefix": "al",
25+
"style": "kebab-case"
26+
}
27+
]
28+
}
29+
},
30+
{
31+
"files": ["*.html"],
32+
"extends": ["plugin:@nx/angular-template"],
33+
"rules": {}
34+
}
35+
]
36+
}

libs/blog-bff/pages/api/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# api
2+
3+
This library was generated with [Nx](https://nx.dev).
4+
5+
## Running unit tests
6+
7+
Run `nx test api` to execute the unit tests.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/* eslint-disable */
2+
export default {
3+
displayName: 'api',
4+
preset: '../../../../jest.preset.js',
5+
setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'],
6+
coverageDirectory: '../../../../coverage/libs/blog-bff/pages/api',
7+
transform: {
8+
'^.+\\.(ts|mjs|js|html)$': [
9+
'jest-preset-angular',
10+
{
11+
tsconfig: '<rootDir>/tsconfig.spec.json',
12+
stringifyContentPathRegex: '\\.(html|svg)$',
13+
},
14+
],
15+
},
16+
transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$)'],
17+
snapshotSerializers: [
18+
'jest-preset-angular/build/serializers/no-ng-attributes',
19+
'jest-preset-angular/build/serializers/ng-snapshot',
20+
'jest-preset-angular/build/serializers/html-comment',
21+
],
22+
};

libs/blog-bff/pages/api/project.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "api-pages",
3+
"$schema": "../../../../node_modules/nx/schemas/project-schema.json",
4+
"sourceRoot": "libs/blog-bff/pages/api/src",
5+
"prefix": "al",
6+
"projectType": "library",
7+
"tags": ["scope:bff", "type:api"],
8+
"targets": {
9+
"test": {
10+
"executor": "@nx/jest:jest",
11+
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
12+
"options": {
13+
"jestConfig": "libs/blog-bff/pages/api/jest.config.ts"
14+
}
15+
},
16+
"lint": {
17+
"executor": "@nx/eslint:lint"
18+
}
19+
}
20+
}

libs/blog-bff/pages/api/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default as pages } from './lib/api';
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { Hono } from 'hono';
2+
3+
import {
4+
appCache,
5+
langMw,
6+
} from '@angular-love/blog-bff/shared/util-middleware';
7+
import { wpClientMw } from '@angular-love/util-wp';
8+
9+
import { toPage } from './mappers';
10+
import { WpPages } from './wp-pages';
11+
12+
const app = new Hono().use(appCache).use(wpClientMw).use(langMw());
13+
14+
app.get('/:slug', async (c) => {
15+
const slug = c.req.param('slug');
16+
const client = new WpPages(c.var.createWPClient());
17+
const result = await client.getBySlug(slug);
18+
19+
return c.json(toPage(result.data[0]));
20+
});
21+
22+
export default app;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
export interface WPPageDto {
2+
slug: string;
3+
title: {
4+
rendered: string;
5+
};
6+
content: {
7+
rendered: string;
8+
};
9+
excerpt: {
10+
rendered: string;
11+
};
12+
other_translations: {
13+
locale: string;
14+
slug: string;
15+
}[];
16+
lang: string;
17+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { Page } from '@angular-love/blog/contracts/pages';
2+
3+
import { WPPageDto } from './dtos';
4+
5+
export const toPage = (dto: WPPageDto): Page => {
6+
return {
7+
slug: dto.slug,
8+
title: dto.title.rendered,
9+
content: dto.content.rendered,
10+
excerpt: dto.excerpt.rendered,
11+
otherTranslations: dto.other_translations || [],
12+
lang: dto.lang,
13+
};
14+
};
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { WPResponse, WPRestClient } from '@angular-love/util-wp';
2+
3+
import { WPPageDto } from './dtos';
4+
5+
export class WpPages {
6+
constructor(private readonly _wpClient: WPRestClient) {}
7+
8+
getBySlug(slug: string): Promise<WPResponse<WPPageDto[]>> {
9+
return this._wpClient.get('pages', { slug: slug });
10+
}
11+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import 'jest-preset-angular/setup-jest';
2+
3+
// @ts-expect-error https://thymikee.github.io/jest-preset-angular/docs/getting-started/test-environment
4+
globalThis.ngJest = {
5+
testEnvironmentOptions: {
6+
errorOnUnknownElements: true,
7+
errorOnUnknownProperties: true,
8+
},
9+
};

libs/blog-bff/pages/api/tsconfig.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es2022",
4+
"forceConsistentCasingInFileNames": true,
5+
"strict": true,
6+
"noImplicitOverride": true,
7+
"noPropertyAccessFromIndexSignature": true,
8+
"noImplicitReturns": true,
9+
"noFallthroughCasesInSwitch": true
10+
},
11+
"files": [],
12+
"include": [],
13+
"references": [
14+
{
15+
"path": "./tsconfig.lib.json"
16+
},
17+
{
18+
"path": "./tsconfig.spec.json"
19+
}
20+
],
21+
"extends": "../../../../tsconfig.base.json",
22+
"angularCompilerOptions": {
23+
"enableI18nLegacyMessageIdFormat": false,
24+
"strictInjectionParameters": true,
25+
"strictInputAccessModifiers": true,
26+
"strictTemplates": true
27+
}
28+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"outDir": "../../../../dist/out-tsc",
5+
"declaration": true,
6+
"declarationMap": true,
7+
"inlineSources": true,
8+
"types": []
9+
},
10+
"exclude": [
11+
"src/**/*.spec.ts",
12+
"src/test-setup.ts",
13+
"jest.config.ts",
14+
"src/**/*.test.ts"
15+
],
16+
"include": ["src/**/*.ts"]
17+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"outDir": "../../../../dist/out-tsc",
5+
"module": "commonjs",
6+
"target": "es2016",
7+
"types": ["jest", "node"]
8+
},
9+
"files": ["src/test-setup.ts"],
10+
"include": [
11+
"jest.config.ts",
12+
"src/**/*.test.ts",
13+
"src/**/*.spec.ts",
14+
"src/**/*.d.ts"
15+
]
16+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"extends": ["../../../.eslintrc.json"],
3+
"ignorePatterns": ["!**/*"],
4+
"overrides": [
5+
{
6+
"files": ["*.ts"],
7+
"extends": [
8+
"plugin:@nx/angular",
9+
"plugin:@angular-eslint/template/process-inline-templates"
10+
],
11+
"rules": {
12+
"@angular-eslint/directive-selector": [
13+
"error",
14+
{
15+
"type": "attribute",
16+
"prefix": "al",
17+
"style": "camelCase"
18+
}
19+
],
20+
"@angular-eslint/component-selector": [
21+
"error",
22+
{
23+
"type": "element",
24+
"prefix": "al",
25+
"style": "kebab-case"
26+
}
27+
]
28+
}
29+
},
30+
{
31+
"files": ["*.html"],
32+
"extends": ["plugin:@nx/angular-template"],
33+
"rules": {}
34+
}
35+
]
36+
}

libs/blog-contracts/pages/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# pages
2+
3+
This library was generated with [Nx](https://nx.dev).
4+
5+
## Running unit tests
6+
7+
Run `nx test pages` to execute the unit tests.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/* eslint-disable */
2+
export default {
3+
displayName: 'pages',
4+
preset: '../../../jest.preset.js',
5+
setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'],
6+
coverageDirectory: '../../../coverage/libs/blog-contracts/pages',
7+
transform: {
8+
'^.+\\.(ts|mjs|js|html)$': [
9+
'jest-preset-angular',
10+
{
11+
tsconfig: '<rootDir>/tsconfig.spec.json',
12+
stringifyContentPathRegex: '\\.(html|svg)$',
13+
},
14+
],
15+
},
16+
transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$)'],
17+
snapshotSerializers: [
18+
'jest-preset-angular/build/serializers/no-ng-attributes',
19+
'jest-preset-angular/build/serializers/ng-snapshot',
20+
'jest-preset-angular/build/serializers/html-comment',
21+
],
22+
};
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "blog-contracts-pages",
3+
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
4+
"sourceRoot": "libs/blog-contracts/pages/src",
5+
"prefix": "al",
6+
"projectType": "library",
7+
"tags": ["scope:shared", "type:contract"],
8+
"targets": {
9+
"test": {
10+
"executor": "@nx/jest:jest",
11+
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
12+
"options": {
13+
"jestConfig": "libs/blog-contracts/pages/jest.config.ts"
14+
}
15+
},
16+
"lint": {
17+
"executor": "@nx/eslint:lint"
18+
}
19+
}
20+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './lib/pages';
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export interface Page {
2+
slug: string;
3+
title: string;
4+
content: string;
5+
excerpt: string;
6+
otherTranslations: {
7+
locale: string;
8+
slug: string;
9+
}[];
10+
lang: string;
11+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import 'jest-preset-angular/setup-jest';
2+
3+
// @ts-expect-error https://thymikee.github.io/jest-preset-angular/docs/getting-started/test-environment
4+
globalThis.ngJest = {
5+
testEnvironmentOptions: {
6+
errorOnUnknownElements: true,
7+
errorOnUnknownProperties: true,
8+
},
9+
};
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es2022",
4+
"forceConsistentCasingInFileNames": true,
5+
"strict": true,
6+
"noImplicitOverride": true,
7+
"noPropertyAccessFromIndexSignature": true,
8+
"noImplicitReturns": true,
9+
"noFallthroughCasesInSwitch": true
10+
},
11+
"files": [],
12+
"include": [],
13+
"references": [
14+
{
15+
"path": "./tsconfig.lib.json"
16+
},
17+
{
18+
"path": "./tsconfig.spec.json"
19+
}
20+
],
21+
"extends": "../../../tsconfig.base.json",
22+
"angularCompilerOptions": {
23+
"enableI18nLegacyMessageIdFormat": false,
24+
"strictInjectionParameters": true,
25+
"strictInputAccessModifiers": true,
26+
"strictTemplates": true
27+
}
28+
}

0 commit comments

Comments
 (0)