Browse Source

Add details to README

master
Thierry 5 years ago
parent
commit
36e9fb4813
6 changed files with 63 additions and 13 deletions
  1. +1
    -1
      .gitignore
  2. +53
    -0
      README
  3. +1
    -5
      config.yml
  4. +4
    -4
      config.yml.dist
  5. +4
    -3
      src/main.go
  6. BIN
      src/pagetoc

+ 1
- 1
.gitignore View File

@@ -1,7 +1,7 @@
*.class
z.*

src/Session.vim
*.vim

# temporary executable generated during development
src/src

+ 53
- 0
README View File

@@ -5,6 +5,59 @@ h1 tags can have embedded a name tags
h2 tags are supposed to contain only text
Developed to learn go

SUMMARY
For a brief description of options :
pagetoc -help

Options can either come from command line or from a configuration file

1. Taking parameters from config files :
pagetoc -config test1
will use the parameters defined in section "test1"

2. Using command line arguments :
pagetoc -dir /path/to/html/files -excludes page1.html:page2.html


DETAILED USAGE

Configuration file is expressed using yaml syntax ; must be called "config.yml"
It is organized in different sections.
Each section contains the values of options.
Example of a section :

test1:
dir: /path/to/dir/containing/html/files
excludes:
- file1.html
- file2.html
toc-css-class: toc
insert-after: </center>
action: save
create-backup: true

To run the program using the options of section "test1" :
pagetoc -config test1

Option "action"
- "save" will generate toc and override the original document ; see also "backup" option.
- "print-toc" will print the generated table of contents for each processed html document ; original documents not modified.
- "print-full" will print the generated html for each processed html document ; original documents not modified.
- "none" : does not modify the documents, just prints a list of processed files.

Options "dir" and "file"
One of these two options must be specified, but not both.
They must contain absolute paths.
If option "dir" is specified, all the .html files located in the directory will be processed.
If option "file" is specified, only one file will be processed.

Option "excludes"
Only relevant if "dir" option is used.

TODO
- ReplaceAllString inappropriate, only one string should be replaced
- replace 0644 by original filemode when re-writing files
- change option mechanism : when config is used with other options,
options should be taken from config
and the other options should override them

+ 1
- 5
config.yml View File

@@ -2,20 +2,16 @@
nfp121:
dir: /home/thierry/dev/jobs/cnam/public-tg-cnam/nfp121/cours
excludes:
- programme.html
- references.html
- z-empty.html
toc-css-class: toc
insert-after: </center>
action: none
action: save
create-backup: true

test:
dir: /home/thierry/dev/tools/utils/pagetoc/z.test/cours
excludes:
- programme.html
- references.html
- z-empty.html
toc-css-class: toc
insert-after: </center>
action: save


+ 4
- 4
config.yml.dist View File

@@ -1,9 +1,9 @@

nfp121:
dir: /home/thierry/dev/jobs/cnam/nfp121-tg/public/cours
test1:
dir: /home/me/path/to/html/files
exclude:
- programme.html
- references.html
- page1.html
- page2.html
toc-css-class: toc
insert-after: </center>
print-or-save: save


+ 4
- 3
src/main.go View File

@@ -75,7 +75,7 @@ func main() {
func computeCommand() (cmd Command, err error) {

// Start filling cmd either from config file or command line arguments
// cmd.files not computed yet
// cmd.files is computed later
if *flag_config != "" {
// if config is provided, overrides all the other flags
cmd, err = loadConfig(*flag_config)
@@ -92,6 +92,8 @@ func computeCommand() (cmd Command, err error) {
cmd.insertAfter = *flag_insertAfter
cmd.backup = *flag_backup
}
fmt.Print(cmd)

// check coherence
if cmd.file == "" && cmd.dir == "" {
@@ -190,7 +192,6 @@ func process(cmd Command) (err error) {
if err != nil {
return err
}

htmlStr := string(tmp)

root, err := html.Parse(file)
@@ -245,7 +246,7 @@ func process(cmd Command) (err error) {
htmlStr = strings.Replace(htmlStr, cmd.insertAfter, cmd.insertAfter+"\n"+toc, 1)
// manage output
if cmd.action == "save" {
file2, err := os.OpenFile(filename, os.O_WRONLY, 0644)
file2, err := os.OpenFile(filename, os.O_WRONLY, 0644) // @todo use os.Create() instead
_, err = file2.WriteString(htmlStr)
if err != nil {
return err


BIN
src/pagetoc View File


Loading…
Cancel
Save