From 792de3c64e0c192f17efc4c84aefedaddd232100 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mime=20=C4=8Cuvalo?= Date: Tue, 16 Jul 2024 12:39:25 +0100 Subject: [PATCH] docs: fix up prev/next for api reference (#4171) small thing that was driving me nuts. prev/next didn't really work. before Screenshot 2024-07-15 at 12 29 45 after Screenshot 2024-07-15 at 12 32 31 ### Change type - [ ] `bugfix` - [ ] `improvement` - [ ] `feature` - [ ] `api` - [x] `other` ### Release notes - Docs: fix up prev/next. --- apps/docs/utils/ContentDatabase.ts | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/apps/docs/utils/ContentDatabase.ts b/apps/docs/utils/ContentDatabase.ts index 96445e89c..8d60df0fa 100644 --- a/apps/docs/utils/ContentDatabase.ts +++ b/apps/docs/utils/ContentDatabase.ts @@ -83,9 +83,16 @@ export class ContentDatabase { // the prev is the article with the same section but one less sectionIndex let prev = await this.db.get
( - `SELECT id, title, categoryId, sectionId, path FROM articles WHERE articles.sectionId = ? AND articles.sectionIndex = ?`, + `SELECT id, title, categoryId, sectionId, path FROM articles + WHERE articles.sectionId = ? + AND ((articles.groupId = ? AND ? IS NOT NULL) OR (articles.groupId IS NULL AND ? is NULL)) + AND articles.sectionIndex < ? + ORDER BY articles.sectionIndex DESC LIMIT 1`, article.sectionId, - sectionIndex - 1 + article.groupId, + article.groupId, + article.groupId, + sectionIndex ) // If there's no next, then get the LAST article from the prev section @@ -104,7 +111,9 @@ export class ContentDatabase { // get the article with the section id and the highest section index prev = await this.db.get
( // here we only need certian info for the link - `SELECT id, title, categoryId, sectionId, path FROM articles WHERE articles.sectionId = ? ORDER BY articles.sectionIndex DESC LIMIT 1`, + `SELECT id, title, categoryId, sectionId, path FROM articles + WHERE articles.sectionId = ? + ORDER BY articles.sectionIndex DESC LIMIT 1`, prevSectionId ) } @@ -112,9 +121,16 @@ export class ContentDatabase { // the next is the article with the same section but next sectionIndex let next = await this.db.get
( - `SELECT id, title, categoryId, sectionId, path FROM articles WHERE articles.sectionId = ? AND articles.sectionIndex = ?`, + `SELECT id, title, categoryId, sectionId, path FROM articles + WHERE articles.sectionId = ? + AND ((articles.groupId = ? AND ? IS NOT NULL) OR (articles.groupId IS NULL AND ? is NULL)) + AND articles.sectionIndex > ? + ORDER BY articles.sectionIndex ASC LIMIT 1`, article.sectionId, - sectionIndex + 1 + article.groupId, + article.groupId, + article.groupId, + sectionIndex ) // If there's no next, then get the FIRST article from the next section @@ -132,7 +148,9 @@ export class ContentDatabase { if (nextSection) { const { id: nextSectionId } = nextSection next = await this.db.get
( - `SELECT id, title, categoryId, sectionId, path FROM articles WHERE articles.sectionId = ? ORDER BY articles.sectionIndex ASC LIMIT 1`, + `SELECT id, title, categoryId, sectionId, path FROM articles + WHERE articles.sectionId = ? + ORDER BY articles.sectionIndex ASC LIMIT 1`, nextSectionId ) }