mirror of
https://github.com/codex-team/codex.docs.git
synced 2025-08-08 06:55:26 +02:00
fix next/prev buttons
This commit is contained in:
parent
432edd6167
commit
8d566c8c78
2 changed files with 6 additions and 5 deletions
|
@ -2,6 +2,7 @@ import Page from './page.js';
|
||||||
import PageOrder from './pageOrder.js';
|
import PageOrder from './pageOrder.js';
|
||||||
import NodeCache from 'node-cache';
|
import NodeCache from 'node-cache';
|
||||||
import { EntityId } from '../database/types.js';
|
import { EntityId } from '../database/types.js';
|
||||||
|
import { isEqualIds } from '../database/index.js';
|
||||||
|
|
||||||
// Create cache for flat array
|
// Create cache for flat array
|
||||||
const cache = new NodeCache({ stdTTL: 120 });
|
const cache = new NodeCache({ stdTTL: 120 });
|
||||||
|
@ -109,7 +110,7 @@ class PagesFlatArray {
|
||||||
public static async getPageBefore(pageId: EntityId): Promise<PagesFlatArrayData | undefined> {
|
public static async getPageBefore(pageId: EntityId): Promise<PagesFlatArrayData | undefined> {
|
||||||
const arr = await this.get();
|
const arr = await this.get();
|
||||||
|
|
||||||
const pageIndex = arr.findIndex( (item) => item.id == pageId);
|
const pageIndex = arr.findIndex((item) => isEqualIds(item.id, pageId));
|
||||||
|
|
||||||
// Check if index is not the first
|
// Check if index is not the first
|
||||||
if (pageIndex && pageIndex > 0) {
|
if (pageIndex && pageIndex > 0) {
|
||||||
|
@ -129,7 +130,7 @@ class PagesFlatArray {
|
||||||
public static async getPageAfter(pageId: EntityId): Promise<PagesFlatArrayData | undefined> {
|
public static async getPageAfter(pageId: EntityId): Promise<PagesFlatArrayData | undefined> {
|
||||||
const arr = await this.get();
|
const arr = await this.get();
|
||||||
|
|
||||||
const pageIndex = arr.findIndex( (item) => item.id == pageId );
|
const pageIndex = arr.findIndex( (item) => isEqualIds(item.id, pageId));
|
||||||
|
|
||||||
// Check if index is not the last
|
// Check if index is not the last
|
||||||
if (pageIndex < arr.length -1) {
|
if (pageIndex < arr.length -1) {
|
||||||
|
@ -153,7 +154,7 @@ class PagesFlatArray {
|
||||||
pages: Array<Page>, orders: Array<PageOrder>): Array<PagesFlatArrayData> {
|
pages: Array<Page>, orders: Array<PageOrder>): Array<PagesFlatArrayData> {
|
||||||
let arr: Array<PagesFlatArrayData> = new Array<PagesFlatArrayData>();
|
let arr: Array<PagesFlatArrayData> = new Array<PagesFlatArrayData>();
|
||||||
|
|
||||||
const page = pages.find( item => item._id == pageId );
|
const page = pages.find(item => isEqualIds(item._id, pageId));
|
||||||
|
|
||||||
// Add element to child array
|
// Add element to child array
|
||||||
if (page) {
|
if (page) {
|
||||||
|
@ -167,7 +168,7 @@ class PagesFlatArray {
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
const order = orders.find(item => item.page == pageId);
|
const order = orders.find(item => isEqualIds(item.page, pageId));
|
||||||
|
|
||||||
if (order) {
|
if (order) {
|
||||||
for (const childPageId of order.order) {
|
for (const childPageId of order.order) {
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
<a
|
<a
|
||||||
class="docs-sidebar__section-list-item-wrapper"
|
class="docs-sidebar__section-list-item-wrapper"
|
||||||
href="{{ child.uri ? '/' ~ child.uri : '/page/' ~ child._id }}">
|
href="{{ child.uri ? '/' ~ child.uri : '/page/' ~ child._id }}">
|
||||||
<div class="docs-sidebar__section-list-item {{page is defined and page._id == child._id ? 'docs-sidebar__section-list-item--active' : ''}}">
|
<div class="docs-sidebar__section-list-item {{page is defined and toString(page._id) == toString(child._id) ? 'docs-sidebar__section-list-item--active' : ''}}">
|
||||||
<span>{{ child.title | striptags }}</span>
|
<span>{{ child.title | striptags }}</span>
|
||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue