condorheroblog / vuepress-plugin-export-pdf

VuePress plugin exports PDF 📁.
MIT License
22 stars 2 forks source link

Can you give some parameters or examples to adjust the output page order? #4

Closed ykla closed 1 year ago

ykla commented 1 year ago

Hi,

In readme, vuepress-plugin-export-pdf-v2 output page order of the wrong.

And the order controlled by sorter. But there is no example or parameter for sorter. So how to change it?

Suppose I have the following files and folders in my documents:

docs folders contains :

A.md
B.md
C.md
AA-------contains 1.md, 2.md  and 3.md
BB-------contains 4.md, 5.md  and 6.md
CC-------contains 7.md, 8.md  and 9.md

and after run export pdf, the HTML files are:

docs folders contains :

A.html
B.html
C.html
AA-------contains 1.html, 2.html  and 3.html
BB-------contains 4.html, 5.html  and 6.html
CC-------contains 7.html, 8.html  and 9.html

How should I sort the above folders using the sorter parameter? Thank you very much for your help.

condorheroblog commented 1 year ago
  1. define router order

It can be obtained by console.log in sorter function

const routeOrder = [
  '/A.html',
  '/B.html',
  '/C.html',
  '/AA/1.html',
  '/AA/2.html',
  '/AA/3.html',
  '/BB/4.html',
  '/BB/5.html',
  '/BB/6.html',
  '/CC/7.html',
  '/CC/8.html',
  '/CC/9.html',
]
  1. sorter
export default defineUserConfig({
  sorter: (pageA, pageB) => {
    const aIndex = routeOrder.findIndex(route => route === pageA.path)
    const bIndex = routeOrder.findIndex(route => route === pageB.path)
    return aIndex - bIndex
  },
})