-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(export): export pdf with outlines if --with-toc
option is specified
#669
feat(export): export pdf with outlines if --with-toc
option is specified
#669
Conversation
packages/slidev/node/export.ts
Outdated
const pdf = fs.readFileSync(output, { encoding: 'base64' }) | ||
const outline = slides.map(({ title }, idx) => | ||
title ? `${idx + 1}||${title}` : null, | ||
).filter(outline => !!outline).join('\n') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't you want to manage the "deepness" of title ?
In that case you may also be interested in the level
property.
Also please heck the following properties (rawTree
, treeWithActiveStatuses
and tree
) from here https://github.com/slidevjs/slidev/blob/main/packages/client/logic/nav.ts#L79-L86
I think It would better to use the same logic and thus the same functions than the ones used for the <Toc>
component
And then having a dedicated renderer for the outline.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your comment! I did not know <Toc />
component. I will refer it and change my logic to use same logic of <Toc />
. However, I am wondering how to use rawTree
in nodejs slidev
because rawTree
is plugged via a vite slidev plugin in client side build. 💭
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sorry for the late response 🙇
I changed to handle "deepness" of title. The current output is like the below.
Also please heck the following properties (rawTree, treeWithActiveStatuses and tree) from here https://github.com/slidevjs/slidev/blob/main/packages/client/logic/nav.ts#L79-L86
I think It would better to use the same logic and thus the same functions than the ones used for the component
And then having a dedicated renderer for the outline.
I agree, but the current logic about <Toc />
is too for the client-side to share the logic also with export
command in CLI…so I am wondering about design.
To share the logic about <Toc />
also with export
command, I searched for a package to share the logic in the client-side and server-side( or command line side), but I could not find that… Do you know such a package for this use case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI: in the current implementation of this PR, the logic about ToC of PDF in export
command is implemented adhocky separated from <Toc />
component's logic in client-side.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Shinyaigeek The idea of reuseing the same functions would be to ensure that the generated TOC will be the same as the one created with the <Toc/>
component.
But yes those functions live in the client package.
@antfu what do you think of having a shared module that could be imported in either the backend or the frontend ?
Or should we duplicate some functions ? (here it is about all 3 addToTree
, getTreeWithActiveStatuses
and filterTree
functions in client/logic/nav.ts
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, as @tonai says, it is better to share the logic which is reusable. If there is no package to share the utility with client-side and CLI, perhaps we should make such a package before promoting this PR.
@condorheroblog Thank you! I feel your concern will be resolved if @tonai’s advice is reflected. |
7cde920
to
ea873e9
Compare
0ef577a
to
cc6bd7d
Compare
cc6bd7d
to
c71367e
Compare
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Not stale |
--with-toc
option is specified--with-toc
option is specified
Motivation 🔥
Fixes: #662
I implemented a feature to export pdf with outlines. A user can generate a pdf with outlines if they specify
--with-toc
option in command line.I happened to see the issue, and it seemed interesting, so I started working on it, but it went better than I expected, so I'm submitting it as a PR. I would like to discuss the implementation policy using this branch as a starting point. Please feel free to comment on any concerns or overlooked points.