Add GA code to HTML.

This commit is contained in:
Greg Hendershott 2012-10-26 09:00:25 -04:00
parent 26c6cb2b84
commit 6c9c7746ea
3 changed files with 36 additions and 1 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
.DS_Store
main.html

33
add-ga.rkt Normal file
View File

@ -0,0 +1,33 @@
#lang racket
;; Realm of kludge:
;;
;; AFIK no way via Scribble to put something into the <head> section.
;;
;; This takes "main.html", adds some GA code, and outputs "index.html".
(define _subst
#<<EOF
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-29709446-1']);
_gaq.push(['_setDomainName', 'greghendershott.com']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</head>
EOF
)
(define subst (regexp-replace* "\n" _subst "")) ;minify
(define old (file->string "main.html"))
(define new (regexp-replace "</head>" old subst))
(with-output-to-file (build-path 'same "index.html")
(lambda () (display new))
#:mode 'text
#:exists 'replace)

View File

@ -1 +1,2 @@
scribble --html ++style gh.css ++xref-in setup/xref load-collections-xref --redirect-main "http://docs.racket-lang.org/" --dest-name index.html main.rkt
scribble --html ++style gh.css ++xref-in setup/xref load-collections-xref --redirect-main "http://docs.racket-lang.org/" main.rkt
racket add-ga.rkt