Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add from RSS plugin #9

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ jobs:
${{ runner.os }}-
- name: Install dependencies
run: yarn install
- name: Run Angular Compatibility Compiler
run: yarn ngcc

- run: yarn test --max-parallel=$NX_MAX_PARALLEL

Expand Down Expand Up @@ -99,8 +97,6 @@ jobs:
${{ runner.os }}-
- name: Install dependencies
run: yarn install
- name: Run Angular Compatibility Compiler
run: yarn ngcc

- run: yarn build --max-parallel=$NX_MAX_PARALLEL
- run: yarn scully
Expand Down Expand Up @@ -168,7 +164,5 @@ jobs:
${{ runner.os }}-
- name: Install dependencies
run: yarn install
- name: Run Angular Compatibility Compiler
run: yarn ngcc

- run: yarn e2e --configuration=ci --max-parallel=$NX_MAX_PARALLEL
1 change: 1 addition & 0 deletions .scully/settings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
identifier: k8p7l5odl6b2cet5
39 changes: 36 additions & 3 deletions angular.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"cli": {
"defaultCollection": "@nrwl/angular"
Expand All @@ -8,14 +7,19 @@
"schematics": {
"@nrwl/angular:application": {
"e2eTestRunner": "cypress",
"inlineStyle": true,
"inlineTemplate": true,
"linter": "eslint",
"prefix": "til",
"style": "scss",
"tags": "type:app",
"unitTestRunner": "jest",
"tags": "type:app",
"viewEncapsulation": "None"
},
"@nrwl/angular:library": {
"changeDetection": "OnPush",
"linter": "eslint",
"prefix": "til",
"style": "scss",
"unitTestRunner": "jest"
},
Expand All @@ -28,6 +32,9 @@
"export": true,
"style": "scss",
"viewEncapsulation": "None"
},
"@nrwl/angular:component": {
"style": "scss"
}
},
"projects": {
Expand All @@ -51,7 +58,8 @@
"apps/this-is-learning/src/assets"
],
"styles": ["apps/this-is-learning/src/styles.scss"],
"scripts": []
"scripts": [],
"allowedCommonJsDependencies": ["rss-parser"]
},
"configurations": {
"production": {
Expand Down Expand Up @@ -163,6 +171,31 @@
}
}
}
},
"publications-feature-this-is-angular": {
"projectType": "library",
"root": "libs/publications/feature-this-is-angular",
"sourceRoot": "libs/publications/feature-this-is-angular/src",
"prefix": "til",
"architect": {
"test": {
"builder": "@nrwl/jest:jest",
"outputs": ["coverage/libs/publications/feature-this-is-angular"],
"options": {
"jestConfig": "libs/publications/feature-this-is-angular/jest.config.js",
"passWithNoTests": true
}
},
"lint": {
"builder": "@nrwl/linter:eslint",
"options": {
"lintFilePatterns": [
"libs/publications/feature-this-is-angular/src/**/*.ts",
"libs/publications/feature-this-is-angular/src/**/*.html"
]
}
}
}
}
}
}
7 changes: 7 additions & 0 deletions apps/this-is-learning/src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ const routes: Routes = [
path: '',
component: HelloComponent,
},
{
path: 'this-is-angular',
loadChildren: () =>
import('@this-is-learning/publications/feature-this-is-angular').then(
(esModule) => esModule.PublicationsFeatureThisIsAngularModule
),
},
];

@NgModule({
Expand Down
16 changes: 14 additions & 2 deletions apps/this-is-learning/src/app/hello/hello.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,32 @@ import {
ViewEncapsulation,
} from '@angular/core';

const selector = 'til-hello';

@Component({
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
selector: 'til-hello',
selector,
styles: [
`
til-hello {
${selector} {
display: block;
}
`,
],
template: `
<h1>Hello, Scully!</h1>
<p>Render time: {{ now | date: 'long' }}</p>

<h2>Publications</h2>

<nav>
<ul>
<li>
<a routerLink="/this-is-angular">This is Angular</a>
</li>
</ul>
</nav>
`,
})
export class HelloComponent {
Expand Down
3 changes: 2 additions & 1 deletion apps/this-is-learning/src/app/hello/hello.scam.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';

import { HelloComponent } from './hello.component';

@NgModule({
declarations: [HelloComponent],
imports: [CommonModule],
imports: [CommonModule, RouterModule],
})
export class HelloScam {}
2 changes: 1 addition & 1 deletion apps/this-is-learning/src/assets/scully-routes.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{ "route": "/" }]
[{"route":"/"},{"route":"/this-is-angular"}]
5 changes: 4 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
module.exports = {
projects: ['<rootDir>/apps/this-is-learning'],
projects: [
'<rootDir>/apps/this-is-learning',
'<rootDir>/libs/publications/feature-this-is-angular',
],
};
36 changes: 36 additions & 0 deletions libs/publications/feature-this-is-angular/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"extends": ["../../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts"],
"extends": [
"plugin:@nrwl/nx/angular",
"plugin:@angular-eslint/template/process-inline-templates"
],
"rules": {
"@angular-eslint/directive-selector": [
"error",
{
"type": "attribute",
"prefix": "til",
"style": "camelCase"
}
],
"@angular-eslint/component-selector": [
"error",
{
"type": "element",
"prefix": "til",
"style": "kebab-case"
}
]
}
},
{
"files": ["*.html"],
"extends": ["plugin:@nrwl/nx/angular-template"],
"rules": {}
}
]
}
1 change: 1 addition & 0 deletions libs/publications/feature-this-is-angular/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# This is Angular publication feature
24 changes: 24 additions & 0 deletions libs/publications/feature-this-is-angular/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module.exports = {
displayName: 'publications-feature-this-is-angular',
preset: '../../../jest.preset.js',
setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'],
globals: {
'ts-jest': {
tsconfig: '<rootDir>/tsconfig.spec.json',
stringifyContentPathRegex: '\\.(html|svg)$',
astTransformers: {
before: [
'jest-preset-angular/build/InlineFilesTransformer',
'jest-preset-angular/build/StripStylesTransformer',
],
},
},
},
coverageDirectory:
'../../../coverage/libs/publications/feature-this-is-angular',
snapshotSerializers: [
'jest-preset-angular/build/serializers/no-ng-attributes',
'jest-preset-angular/build/serializers/ng-snapshot',
'jest-preset-angular/build/serializers/html-comment',
],
};
1 change: 1 addition & 0 deletions libs/publications/feature-this-is-angular/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './lib/publications-feature-this-is-angular.module';
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { ChangeDetectionStrategy, Component, Input, ViewEncapsulation } from '@angular/core';

import { DevCommunityRssItem } from '../dev-community-rss-parser.token';

const selector = '[til-article]';

@Component({
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
selector,
template: `
<h2>
<a [href]="rssItem?.link" target="_blank" rel="nofollow noopener">{{
rssItem?.title
}}</a>
</h2>

<footer>
<p>
By {{ rssItem?.author }}<br />
<time [dateTime]="rssItem?.isoDate">{{
rssItem?.isoDate | date: 'long'
}}</time
><br />
<span *ngFor="let tag of rssItem?.categories">#{{ tag }} </span>
</p>
</footer>

<p>{{ rssItem?.contentSnippet | tilTruncate }}</p>

<a [href]="rssItem?.link" target="_blank" rel="nofollow noopener"
>Read article</a
>
`,
})
export class ArticleComponent {
@Input()
rssItem: DevCommunityRssItem | null = null;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';

import { TruncateScam } from '../truncate/truncate.scam';
import { ArticleComponent } from './article.component';

@NgModule({
declarations: [ArticleComponent],
exports: [ArticleComponent],
imports: [CommonModule, TruncateScam],
})
export class ArticleScam {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Inject, Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, Resolve } from '@angular/router';

import { DevCommunityRssItems, DevCommunityRssParser, devCommunityRssParserToken } from './dev-community-rss-parser.token';

@Injectable({
providedIn: 'root',
})
export class DevCommunityRssItemsResolver
implements Resolve<DevCommunityRssItems> {
constructor(
@Inject(devCommunityRssParserToken) private rssParser: DevCommunityRssParser
) {}

async resolve(route: ActivatedRouteSnapshot): Promise<DevCommunityRssItems> {
const feed = await this.rssParser.parseURL(route.data.rssUrl);

return feed.items;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { InjectionToken } from '@angular/core';
import * as RssParser from 'rss-parser';

export interface DevCommunityRssFeedCustomFields {
readonly language: string;
}

export interface DevCommunityRssItemCustomFields {
readonly author: string;
readonly contentSnippet: string;
readonly description: string;
}

export type DevCommunityRssParser = RssParser<
DevCommunityRssFeedCustomFields,
DevCommunityRssItemCustomFields
>;

export type DevCommunityRssItem = DevCommunityRssItemCustomFields &
RssParser.Item;
export type DevCommunityRssItems = readonly DevCommunityRssItem[];

export function devCommunityRssParserFactory(): DevCommunityRssParser {
return new RssParser<
DevCommunityRssFeedCustomFields,
DevCommunityRssItemCustomFields
>({
customFields: {
feed: ['language'],
item: ['author', 'contentSnippet', 'description'],
},
});
}

export const devCommunityRssParserToken = new InjectionToken<DevCommunityRssParser>(
'DEV_Community_RSS_parser',
{
factory: devCommunityRssParserFactory,
providedIn: 'root',
}
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { NgModule } from '@angular/core';

import { ShellModule } from './shell/shell.module';

@NgModule({
imports: [ShellModule],
})
export class PublicationsFeatureThisIsAngularModule {}
Loading