Re: text to html

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 3 July 2010 11:09, Jozsi Avadkan <jozsi.avadkan@xxxxxxxxx> wrote:
> it will be a site, were i put my notes

I'll give you the benefit of the doubt based on the fact a quick
Google search says you ask questions a lot and they don't all look
like homework ;o)

If you have the filenames in a file, you can do this:

cat list.txt | ( function title { echo "<br><font
size=4>$1</font><br>" ; } ; function ending { echo "<br>" ; };
function link { LINK=$1 ; LINKFILE=${LINK##*/} ;
LINKNAME=${LINKFILE%.html} ; echo "<a href=\"$LINK\">$LINKNAME</a> |"
; } ; PREVTITLE="" ; TITLE="" ; while read line; do
TITLE="${line%%/*}" ; if [ "$TITLE" != "$PREVTITLE" ]; then if [
"$PREVTITLE" != "x" ]; then ending "" ; fi ; title $TITLE ;
PREVTITLE=$TITLE ; fi ; link $line ; done ; )

 If you have a tree of links, you could replace "cat list.txt" with
"find ./ -type f"

The pretty version looks like this:

##################################################
#!/bin/bash

function title {
   echo "<br><font size=4>$1</font><br>"
}

function ending {
   echo "<br>"
}

function link {
   # prints out the link template given the path to link to
   LINK=$1
   # delete the longest match of */ from the left side of the path, to
give the filename (equivalent to running `basename $LINK`)
   LINKFILE=${LINK##*/}
   # delete the shortest match of .html from the right of the
filename, to give the name of the link (equivalent to `echo $LINKNAME
| sed -e 's/\.html//g'`
   LINKNAME=${LINKFILE%.html}
   echo "<a href=\"$LINK\">$LINKNAME</a> |"
}

# set the variables to detect a title change
PREVTITLE=""
TITLE=""

# start processing STDIN
while read line;
do
#  deletes the longest match of /* from the right of the path, to
generate the category title, equivalent to `echo $link | cut -d/ -f1`
TITLE=${line%%/*}
   if [ "$TITLE" != "$PREVTITLE" ]; then
      if [ "$PREVTITLE" != "" ]; then
         # only print the <br> on title change and not at start of loop.
         ending
      fi
      title $TITLE
      PREVTITLE=$TITLE
   fi
   link $line
done
###########################################


-- 
Sam
-- 
users mailing list
users@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux