Skip to content

Commit

Permalink
feat: add page viewer component and move about to markdown file
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonroberts committed Mar 11, 2019
1 parent 8cfd447 commit abf1c68
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 48 deletions.
5 changes: 2 additions & 3 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { MarkdownModule } from 'ngx-markdown';

import { AppComponent } from './app.component';
import { CoreModule } from './core/core.module';
import { PageNotFoundComponent, AboutComponent } from './core/components';
import { PageNotFoundComponent, PageComponent } from './core/components';

@NgModule({
declarations: [
Expand All @@ -20,9 +20,8 @@ import { PageNotFoundComponent, AboutComponent } from './core/components';
RouterModule.forRoot([
{ path: '', redirectTo: '/blog', pathMatch: 'full' },
{ path: 'blog', loadChildren: './blog/blog.module#BlogModule' },
{ path: 'about', component: AboutComponent },
{ path: '404', component: PageNotFoundComponent },
{ path: '**', component: PageNotFoundComponent }
{ path: ':pageId', component: PageComponent },
]),
MarkdownModule.forRoot(),
CoreModule
Expand Down
40 changes: 0 additions & 40 deletions src/app/core/components/about/about.component.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/app/core/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from './about/about.component';
export * from './layout/layout.component';
export * from './page/page.component';
export * from './page-not-found/page-not-found.component';
44 changes: 44 additions & 0 deletions src/app/core/components/page/page.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { tap, switchMap } from 'rxjs/operators';

import { PageService } from 'src/app/core/services';

@Component({
selector: 'app-page',
template: `
<markdown [data]="page$ | async"></markdown>
`,
styles: [
`
:host {
display: flex;
width: 80%;
}
markdown {
width: 100%;
}
`
]
})
export class PageComponent implements OnInit {
page$ = this.route.paramMap.pipe(
switchMap(params =>
this.postService.getPageContent(params.get('pageId'))
.pipe(tap(() => {}, () => {
this.router.navigate(['/404']);
}))
)
);

constructor(
private router: Router,
private route: ActivatedRoute,
private postService: PageService
) { }

ngOnInit() {
}

}
10 changes: 6 additions & 4 deletions src/app/core/core.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ import { CommonModule } from '@angular/common';
import { LayoutModule } from '@angular/cdk/layout';
import { MatToolbarModule, MatButtonModule, MatSidenavModule, MatIconModule, MatListModule } from '@angular/material';
import { RouterModule } from '@angular/router';
import { MarkdownModule } from 'ngx-markdown';

import { LayoutComponent, PageNotFoundComponent, AboutComponent } from './components';
import { LayoutComponent, PageNotFoundComponent, PageComponent } from './components';
import { FooterModule } from '../shared/footer';

@NgModule({
declarations: [
LayoutComponent,
PageNotFoundComponent,
AboutComponent
PageComponent,
PageNotFoundComponent
],
imports: [
CommonModule,
Expand All @@ -22,7 +23,8 @@ import { FooterModule } from '../shared/footer';
MatSidenavModule,
MatIconModule,
MatListModule,
FooterModule
FooterModule,
MarkdownModule.forChild()
],
exports: [
LayoutComponent
Expand Down
1 change: 1 addition & 0 deletions src/app/core/services/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './page.service';
export * from './post.service';
14 changes: 14 additions & 0 deletions src/app/core/services/page.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';

@Injectable({
providedIn: 'root'
})
export class PageService {

constructor(private http: HttpClient) { }

getPageContent(pageId: string) {
return this.http.get(`/content/pages/${pageId}.md`, { responseType: 'text' });
}
}
16 changes: 16 additions & 0 deletions src/content/pages/about.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<div class="page about-page">

## About Me

<div class="pic">
<img src="/assets/images/brandonroberts.jpg" width="300" height="300"/>
</div>

<p class="bio">
I am an Angular Team member working on guides, tutorials, application development,
and infrastructure for the Angular docs. I enjoys learning new things, helping other
developers solve problems, and contributing to open source. I am also a maintainer of the
NgRx project, building reactive libraries for Angular.
</p>

</div>
10 changes: 10 additions & 0 deletions src/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,14 @@ a {

h2 {
font-weight: normal;
}


div.page {
width: 80%;
}

div.about-page .pic {
display: flex;
justify-content: space-around;
}

0 comments on commit abf1c68

Please sign in to comment.