寻找 HTML 目录生成器

发布于 2024-10-25 13:38:08 字数 1539 浏览 1 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

北斗星光 2024-11-01 13:38:08

作为 @user5858 提到的 htmltoc 脚本的替代方案,有 hypertoc,一个更强大的重写,同样是用 Perl 完成的。像这样安装它(例如在 Ubuntu Linux 上):

sudo cpan -f -i HTML::GenToc

像这样使用它:

hypertoc --inline --make_anchors --make_toc --overwrite file.html

As an alternative to the htmltoc script mentioned by @user5858, there is hypertoc, a more powerful rewrite of the same, again done with Perl. Install it like this (on Ubuntu Linux for example):

sudo cpan -f -i HTML::GenToc

Use it like this:

hypertoc --inline --make_anchors --make_toc --overwrite file.html
薄情伤 2024-11-01 13:38:08

我刚刚写了一个 关于使用 hypertoc、sed 和 make 为 HTML 页面生成目录的博客文章。 shell 脚本还使用广告名称插入 Google 广告。我还创建了一个 导航部分 可用于导航到网站上的其他页面。

我使用的网页示例模板如下所示:

<!-- INCLUDE Navigation -->
<div id="centerDoc">
<h1>Title</h1>
<!-- Insert an ad -->
<!-- INCLUDE GoogleAd1 -->
<!-- Insert the table of contents here -->
<!--toc-->
<h2>More HTML code here</h2>

我编写了一个名为 include 的脚本,该脚本读取名为 *.html.in 的文件并创建一个 *.html 文件。脚本看起来像这样。我还使用 makefile 将 *.html.in 文件转换为 *.html 文件

#!/bin/sh
#This script modifies HTML pages staticly, using something similar 
# to the "#INCLUDE" C preprocessor mechanism
INCLUDE=${1?'Missing include file'}
shift
IFILE=${1?'Missing input file'}
OFILE=`echo $IFILE  | sed 's/\.in$//'`
# get the name without the path
OFILENAME=`echo $OFILE  | sed 's:.*/::'`
if [ "$IFILE" = "$OFILE" ]
then
    echo input file $IFILE same as output file $OFILE - exit
    exit
fi

ARGS="--toc_entry 'H1=1' --toc_end 'H1=/H1' --toc_entry 'H2=2' --toc_end 'H2=/H2'  --toc_entry 'H3=3' --toc_end 'H3=/H3'  --toc_entry 'H4=4' --toc_end 'H4=/H4' --toc_entry 'H5=5' --toc_end 'H5=/H5'"
# The string !--toc-- is used as a marker to insert the new Table of Contents
TOC="--toc_tag '!--toc--' --toc_tag_replace"
eval hypertoc $ARGS $TOC --make_anchors --make_toc --inline --outfile - $IFILE| \
sed "/<!-- INCLUDE [Nn]avigation/ r $INCLUDE
# Quick and dirty way to add a way to get back to the Toc from an Entry
# 1) put a marker in the beginning of the ToC
    s/<h1>Table of Contents/<h1><a name=\"TOC\">Table Of Contents/
# 2) Add a link back to the ToC from each entry
    s:\(<h[1234]>\)<a name=:\1<a href=\"$OFILENAME#TOC\" name=:g
# Include ad named 'GoogleAd1'
    /INCLUDE GoogleAd1/ {
    r Ads/GoogleAd1
    }
" >$OFILE

I just wrote a blog post on generating table of contents for an HTML page using hypertoc, sed, and make. The shell script also inserts google ads using an ad name. I also created a navigation section that can be used to navigate to other pages on the web site.

The sample template of a web page I use looks something like this:

<!-- INCLUDE Navigation -->
<div id="centerDoc">
<h1>Title</h1>
<!-- Insert an ad -->
<!-- INCLUDE GoogleAd1 -->
<!-- Insert the table of contents here -->
<!--toc-->
<h2>More HTML code here</h2>

I wrote a script called include that reads a file named *.html.in and created a *.html file. The script looks like this. I also used a makefile to convert the *.html.in files into the *.html files

#!/bin/sh
#This script modifies HTML pages staticly, using something similar 
# to the "#INCLUDE" C preprocessor mechanism
INCLUDE=${1?'Missing include file'}
shift
IFILE=${1?'Missing input file'}
OFILE=`echo $IFILE  | sed 's/\.in$//'`
# get the name without the path
OFILENAME=`echo $OFILE  | sed 's:.*/::'`
if [ "$IFILE" = "$OFILE" ]
then
    echo input file $IFILE same as output file $OFILE - exit
    exit
fi

ARGS="--toc_entry 'H1=1' --toc_end 'H1=/H1' --toc_entry 'H2=2' --toc_end 'H2=/H2'  --toc_entry 'H3=3' --toc_end 'H3=/H3'  --toc_entry 'H4=4' --toc_end 'H4=/H4' --toc_entry 'H5=5' --toc_end 'H5=/H5'"
# The string !--toc-- is used as a marker to insert the new Table of Contents
TOC="--toc_tag '!--toc--' --toc_tag_replace"
eval hypertoc $ARGS $TOC --make_anchors --make_toc --inline --outfile - $IFILE| \
sed "/<!-- INCLUDE [Nn]avigation/ r $INCLUDE
# Quick and dirty way to add a way to get back to the Toc from an Entry
# 1) put a marker in the beginning of the ToC
    s/<h1>Table of Contents/<h1><a name=\"TOC\">Table Of Contents/
# 2) Add a link back to the ToC from each entry
    s:\(<h[1234]>\)<a name=:\1<a href=\"$OFILENAME#TOC\" name=:g
# Include ad named 'GoogleAd1'
    /INCLUDE GoogleAd1/ {
    r Ads/GoogleAd1
    }
" >$OFILE
空宴 2024-11-01 13:38:08

samaxesjs TOC jQuery 插件 效果非常好。

The samaxesjs TOC jQuery plugin works pretty well.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文