How to generate TOC with links to pdf library? SOLVED

User avatar
Flash
Moderator
Posts: 916
Joined: Tue Dec 03, 2019 3:13 pm
Location: Arizona, U.S.
Has thanked: 47 times
Been thanked: 111 times

Re: How to generate TOC with links to pdf library?

Post by Flash »

I think you don't need to use the - before each option when specifying multiple options. For instance, instead of 'tree -l -H' you could go 'tree -lH' and it will work the same. I think.

Chaos coordinator :?
geo_c
Posts: 2608
Joined: Fri Jul 31, 2020 3:37 am
Has thanked: 1876 times
Been thanked: 744 times

Re: How to generate TOC with links to pdf library?

Post by geo_c »

I need to find a really good, smart and concise linux command line course. I try to figure out these web articles on globbing and such, but I just don't have the basics enough to make it work. I'm not afraid to look at command line --help options and config scripts and try and take a stab in the dark, but that just doesn't cut it for trying to accomplish something serious.

geo_c
Old School Hipster, and Such

User avatar
MochiMoppel
Posts: 1145
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 18 times
Been thanked: 376 times

Re: How to generate TOC with links to pdf library?

Post by MochiMoppel »

geo_c wrote: Thu Aug 19, 2021 8:35 pm

I don't think we want to use the -l option, because that says to follow the link as a directory, so it's probably doing what we're asking in a sense. Appending the directory to include the link target.

Well, that's not what we are asking. It should not append the link target, it should replace baseHREF with the link target. The crappy -l option only works - as you already noticed - for the baseHREF "/" or when the link is a relative directory link, e.g. if the link target for /root/puppy-reference/audio would be '../../usr/share/audio' instead of '/usr/share/audio'. Not using the -l option is indeed the best choice.

User avatar
MochiMoppel
Posts: 1145
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 18 times
Been thanked: 376 times

Re: How to generate TOC with links to pdf library?

Post by MochiMoppel »

@geo_c Here an example how to use a "header" file and inject it into the HTML file created by tree.

1) Create a text file /opt/header.txt with the content

Code: Select all

*         { color:white; font-family:sans }
h1,p      { background-color:DarkSlateGray; padding:10px; border:7px outset DarkSlateGray }
a         { text-decoration:none }
a:hover   { color:black; background-color:yellow }
.VERSION  { display:none }
.DIR      { background-color:darkgreen; border:2px solid white; font-weight:bold; padding:0px 10px 0px 10px }

I played a bit with style rules and the result is not exactly a masterpiece, but it may give an idea how to format some of the page elements. Feel free to experiment and use your own header file. Note that for using the DIR and VERSION classes your tree command must use the -C option.

2) Run the command

Code: Select all

tree --dirsfirst -T "Puppy's Pixmaps" -CH /usr/share/pixmaps /usr/share/pixmaps | sed '/<!--/,/-->/d; /<style/r /opt/header.txt' > /opt/trial.htm

This will create the HTML file /opt/trial.htm which, when opened in PaleMoon, looks like in the screenshot.

What the sed command does:
- It searches for the block that contains <!-- in its first line and --> in its last line. There is only one such block within the <style> section.
- Then it deletes the block, leaving the line <style type="text/css">, followed by line </style>
- In the last step it reads the file /opt/header.txt and places its content after the line containing <style, in effect filling the <style> section with the header file, then writes the result to /opt/trial.

treetest.png
treetest.png (39.04 KiB) Viewed 393 times
geo_c
Posts: 2608
Joined: Fri Jul 31, 2020 3:37 am
Has thanked: 1876 times
Been thanked: 744 times

Re: How to generate TOC with links to pdf library?

Post by geo_c »

@MochiMoppel , thanks I understand.

It was the sed command I was thinking of earlier, now that I see it with proper syntax, I think I can utilize it.

Just one point of clarity I am missing: When running the tree command from a different directory than the href directory, does the first instance of /usr/share/pixmaps serve as the argument for -H, and the second instance of /usr/share/pixmaps says to execute tree from that directory? Or the other way around, or something different entirely?

And one last question. Can the file containg the string for sed to read be located anywhere, did you just used /opt/ as an example?

@geo_c

Last edited by geo_c on Sat Aug 21, 2021 10:56 pm, edited 1 time in total.

geo_c
Old School Hipster, and Such

geo_c
Posts: 2608
Joined: Fri Jul 31, 2020 3:37 am
Has thanked: 1876 times
Been thanked: 744 times

Re: How to generate TOC with links to pdf library?

Post by geo_c »

Okay I made this work. I think it definitely required that the sed replacement file be in /opt. I put some of my tweaks in a text file in /opt called SED-HEADER-tweak.txt. After running that a few times and noticing it returned the top path as an entry on the page, which I don't ultimately want, I decided to combine it with my two step script and make the top a relative path again. So the script came out like this:

Code: Select all

cd /mnt/home/dbox.sync.mir/lib.pdf/cov.lib

tree -H ./ --dirsfirst -T "Table of Contents" -C /mnt/home/dbox.sync.mir/lib.pdf/cov.lib | sed '/<!--/,/-->/d; /<style/r /opt/SED-HEADER-tweak.txt' > /mnt/home/dbox.sync.mir/lib.pdf/cov.lib/ALL-CONTENTS.html

And generated a file that displays like this:
Image

If there is a one step method to get the relative path achieved, I'll use that instead. I'm still using scripts though.

EDIT: I did one more thing. I figured out that symlinks placed underneath the top relative href path actually work. And I have a directory called "A Look At What's New," which is populated with links to files in the other directories. So as I add files I can throw links to them in that folder, and send out the update in a zip file. After every update I can empty that folder and start adding new ones again.

geo_c
Old School Hipster, and Such

User avatar
MochiMoppel
Posts: 1145
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 18 times
Been thanked: 376 times

Re: How to generate TOC with links to pdf library?

Post by MochiMoppel »

geo_c wrote: Sat Aug 21, 2021 10:54 pm

Okay I made this work. I think it definitely required that the sed replacement file be in /opt.

Definitely not. Can be anywhere. I just use /opt because it's empty in my Puppy and a convenient place for experiments.

Does your script really work? You don't need to repeat the path when you use cd and using './' instead of '.' results here in unusable links.
Try this:

Code: Select all

MYDIR=/mnt/home/dbox.sync.mir/lib.pdf/cov.lib
cd $MYDIR
tree -H . --dirsfirst -T "Table of Contents" -C | sed '/<!--/,/-->/d; /<style/r /opt/SED-HEADER-tweak.txt' > $MYDIR/ALL-CONTENTS.html

I'm still using scripts though, because it is a lot to type everytime regardless.

???
The oneliner is a script which you can either paste into a console are put into a script file, but should not type unless you are a masochist.

A script file is certainly the way to go. Would allow you to tweak the HTML file even further and most of all get rid of the separate header file.

And yes, symlinked files work, but not symlinked directories.

geo_c
Posts: 2608
Joined: Fri Jul 31, 2020 3:37 am
Has thanked: 1876 times
Been thanked: 744 times

Re: How to generate TOC with links to pdf library?

Post by geo_c »

MochiMoppel wrote: Sun Aug 22, 2021 1:20 am

Definitely not. Can be anywhere. I just use /opt because it's empty in my Puppy and a convenient place for experiments.

Does your script really work? You don't need to repeat the path when you use cd and using './' instead of '.' results here in unusable links.

A script file is certainly the way to go. Would allow you to tweak the HTML file even further and most of all get rid of the separate header file.

Thanks, I will try that new approach just to learn some more.

My script is working with the path added, but I took it out just to check and it's working also. So for whatever reason, it seems to work either way, and it's including symlinks as well (as I noted above with an edit.) The separate text file is kind of cool because I can just edit that and re-run the script. But it sounds as if you're saying I could just include the header info in the script. That might be cool too.

So here's the script without the extra path added, that's still working well, adding symlinks:

Code: Select all

cd /mnt/home/dbox.sync.mir/lib.pdf/cov.lib

tree -H ./ --dirsfirst -T "Table of Contents" -C | sed '/<!--/,/-->/d; /<style/r /opt/SED-HEADER-tweak.txt' > /mnt/home/dbox.sync.mir/lib.pdf/cov.lib/ALL-CONTENTS.html
Last edited by geo_c on Sun Aug 22, 2021 2:41 am, edited 1 time in total.

geo_c
Old School Hipster, and Such

geo_c
Posts: 2608
Joined: Fri Jul 31, 2020 3:37 am
Has thanked: 1876 times
Been thanked: 744 times

Re: How to generate TOC with links to pdf library?

Post by geo_c »

And I ditched the indentation lines:

Image

geo_c
Old School Hipster, and Such

geo_c
Posts: 2608
Joined: Fri Jul 31, 2020 3:37 am
Has thanked: 1876 times
Been thanked: 744 times

Re: How to generate TOC with links to pdf library?

Post by geo_c »

Okay, @MochiMoppel and @Flash,

I edited the script to use the much more sensible MYDIR command, and cleaned up all the file names and locations.

The end result is a clean simple script run with the bash line: up-covlib

It yields an html tree page formatted to my taste, listing directories and file-links under a relative href path specified by MYDIR.

Organizational features include:

  • A "What's New" directory populated with sym-links to the target files located in the categorized directory structure.

  • An additional script up-covlib-NL to also create the Table of Contents with no links

  • No indentation lines for a clean look.

I had a request for the Library today, this morning, so I created the Table of Contents, zipped the entire directory and uploaded to the cloud. I sent an email with directions and link for download, use of the Table of Contents and an attached Table of Contents with no-links to be used as a preview of the contents by the recipient.

I was immediately replied to with a request to share the no-links Table of Contents with others in their office.

Mission Accomplished

thanks greatly for all the help with this. I never would have known tree had the ability to aid this task.

I'm ready to compose a post for the How-to section of the forum. When I have the time and energy.

geo_c
Old School Hipster, and Such

Post Reply

Return to “Off-Topic Area”