Skip to content

Commit

Permalink
-norandom for normal clicking on image
Browse files Browse the repository at this point in the history
  • Loading branch information
mpl committed Aug 22, 2010
1 parent 8b3fbb3 commit 27839fc
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
14 changes: 13 additions & 1 deletion html.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"os"
"path"
"regexp"
)

const basicTemplates = ".tmpl"
Expand All @@ -25,6 +26,9 @@ pic_html = `
<a href="http://{host}{tags}"> tags </a>
</td>
<td>
<a href="http://{host}/random"> rand </a>
</td>
<td>
<a href="http://{host}/next"> next </a>
</td>
</table>
Expand All @@ -34,7 +38,7 @@ pic_html = `
<div>
<center>
<a href="http://{host}/random">
<img src="http://{host}/{title}" alt={title} />
<img src="http://{host}/{title}" alt="{title}" />
</a>
</center>
</div>
Expand Down Expand Up @@ -105,6 +109,14 @@ func mkTemplates(dirpath string) os.Error {
return err
}

if *norand {
randHtml := regexp.MustCompile(`<a href="http://{host}/random">
`)
pic_html = randHtml.ReplaceAllString(pic_html,
`<a href="http://{host}/{title}">
`)
}

tmpls := [][2]string{[2]string{pic_html, picTmpl}, [2]string{tag_html, tagTmpl}, [2]string{tags_html, tagsTmpl}, [2]string{upload_html, uploadTmpl}}
for _, tmpl := range tmpls {
templ, err := os.Open(path.Join(dirpath, tmpl[1]), os.O_CREAT|os.O_WRONLY, 0644)
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ var (
picsdir = flag.String("picsdir", "./", "Root dir for all the pics")
thumbsize = flag.String("thumbsize", "200x300", "size of the thumbnails")
tmpldir = flag.String("tmpldir", "", "dir for the templates. generates basic ones in " + basicTemplates + " by default")
norand = flag.Bool("norand", false, "disable random when clicking on image")
)

func mkdir(dirpath string) os.Error {
Expand Down
5 changes: 4 additions & 1 deletion tmpl/pic.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
<a href="http://{host}{tags}"> tags </a>
</td>
<td>
<a href="http://{host}random"> rand </a>
</td>
<td>
<a href="http://{host}/next"> next </a>
</td>
</table>
Expand All @@ -19,7 +22,7 @@
<div>
<center>
<a href="http://{host}/random">
<img src="http://{host}/{title}" alt={title} />
<img src="http://{host}/{title}" alt="{title}" />
</a>
</center>
</div>
Expand Down

0 comments on commit 27839fc

Please sign in to comment.