Skip to content

Commit

Permalink
fix(template): update get doc item by path for lite mode (#229)
Browse files Browse the repository at this point in the history
  • Loading branch information
wszgrcy committed Sep 15, 2021
1 parent 41f2a5e commit b2925e0
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
1 change: 1 addition & 0 deletions packages/template/src/services/navigation.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ describe('NavigationService', () => {
});

it('should get doc item by path [intro/getting-started] success', () => {
spectator.service.selectChannelByPath('guides');
const docItem = spectator.service.getDocItemByPath('intro/getting-started');
expect(docItem).toEqual({
id: 'getting-started',
Expand Down
2 changes: 1 addition & 1 deletion packages/template/src/services/navigation.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class NavigationService {
}
} else {
index = this.docItems.findIndex(docItem => {
return docItem.path === path;
return docItem.path === path && (this.global.config.mode === 'lite' ? true : !docItem.channelPath);
});
}
if (index > -1) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="dg-pages-link">
<div class="dg-page-link" *ngIf="docPages.pre && docPages.pre.channelPath">
<a [routerLink]="['/' + docPages.pre.channelPath + '/' + docPages.pre.path]">
<a [routerLink]="[preRouterLink]">
<div class="dg-page-link-icon">
<dg-icon iconName="arrowLeft"></dg-icon>
</div>
Expand All @@ -15,7 +15,7 @@
</a>
</div>
<div class="dg-page-link" *ngIf="docPages.next && docPages.next.channelPath">
<a [routerLink]="['/' + docPages.next.channelPath + '/' + docPages.next.path]">
<a [routerLink]="[nextRouterLink]">
<div class="dg-page-link-icon">
<dg-icon iconName="arrowRight"></dg-icon>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,32 @@
import { Component, Input } from '@angular/core';
import { Component, Input, OnInit } from '@angular/core';
import { NavigationItem } from '@docgeni/template';
import { GlobalContext } from '@docgeni/template/services/public-api';

@Component({
selector: 'dg-doc-pages-links',
templateUrl: './doc-pages-links.component.html'
})
export class DocPagesLinksComponent {
export class DocPagesLinksComponent implements OnInit {
@Input() docPages: {
pre: NavigationItem;
next: NavigationItem;
};
constructor() {}
preRouterLink: string;
nextRouterLink: string;
constructor(private globalContext: GlobalContext) {}

ngOnInit(): void {
if (this.docPages.pre) {
this.preRouterLink =
this.globalContext.config.mode === 'lite'
? `/${this.docPages.pre.path}`
: `/${this.docPages.pre.channelPath}/${this.docPages.pre.path}`;
}
if (this.docPages.next) {
this.nextRouterLink =
this.globalContext.config.mode === 'lite'
? `/${this.docPages.next.path}`
: `/${this.docPages.next.channelPath}/${this.docPages.next.path}`;
}
}
}

0 comments on commit b2925e0

Please sign in to comment.