Skip to content

Commit

Permalink
Removed the pagination identifier prefix.
Browse files Browse the repository at this point in the history
  • Loading branch information
flik1337 committed Sep 13, 2024
1 parent f199e49 commit 2a6702c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,12 @@ function buildPaginationFile(filePath, buildDir, url, keyName, pagination){
containsMagicLast = true
}
// Generate the file path for the current page
let pageFileDir = path.join(buildDir, keyName, 'pgn', `${pageNo}`);
// let pageFileDir = path.join(buildDir, keyName, 'pgn', `${pageNo}`);
let pageFileDir = path.join(buildDir, keyName, `${pageNo}`);

fs.mkdirSync(pageFileDir, { recursive: true });
fs.writeFileSync(path.join(pageFileDir, 'index.html'), pageContent);
// 额外为page0设置非/pgn的访问
// default : no /pageNo
if (pageNo == 0){
const newBuildDir = path.join(buildDir, keyName);
fs.writeFileSync(path.join(newBuildDir, 'index.html'), pageContent);
Expand Down
4 changes: 3 additions & 1 deletion src/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ module.exports = {

// Regex to extract page number from the route.
let pageNo = null;
const pageRegex = /\/pgn\/(\d+)/;
// const pageRegex = /\/pgn\/(\d+)/;
const pageRegex = /\/(\d+)/;

isPaginationRoute = false;
const containsPageNo = route.match(pageRegex); // route = /posts/page/0
if ( containsPageNo ){
Expand Down
8 changes: 6 additions & 2 deletions src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ module.exports = {

processCollectionLoops(template, filePath, pageNo, pagination) {
const { route, pageSize, iteratorKey } = pagination || {}; // Destructure pagination details

// Regular expression to capture the ForEach sections
const loopRegex = /<ForEach\s+([^>]+)>([\s\S]*?)<\/ForEach>/g;

Expand Down Expand Up @@ -501,7 +501,11 @@ module.exports = {
jsonData = pageData;

// Generate pagination links
const { prevLink, nextLink } = this.generatePaginationLinks(isFirstPage, isLastPage, pageNo, '/posts/pgn/');
// const { prevLink, nextLink } = this.generatePaginationLinks(isFirstPage, isLastPage, pageNo, '/posts/');
routeMatch = route.endsWith('/') ? route : route + '/'

const { prevLink, nextLink } = this.generatePaginationLinks(isFirstPage, isLastPage, pageNo, routeMatch);

if (extractedPaginator != null
&& extractedPaginator.includes("prev")
&& extractedPaginator.includes("next") ){
Expand Down

0 comments on commit 2a6702c

Please sign in to comment.