aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/htaccess.in24
-rw-r--r--doc/index.php60
-rwxr-xr-xgendoc.py18
3 files changed, 40 insertions, 62 deletions
diff --git a/doc/htaccess.in b/doc/htaccess.in
new file mode 100644
index 0000000..43c3002
--- /dev/null
+++ b/doc/htaccess.in
@@ -0,0 +1,24 @@
+# Turn off MultiViews
+Options -MultiViews
+
+# Ensure *.ttl files are served as appropriate content type
+AddType text/turtle .ttl
+
+# Rewrite engine setup
+RewriteEngine On
+RewriteBase @BASE@
+
+# Rewrite rule to serve HTML content from the vocabulary URI if requested
+RewriteCond %{HTTP_ACCEPT} !application/rdf\+xml.*(text/html|application/xhtml\+xml)
+RewriteCond %{HTTP_ACCEPT} text/html [OR]
+RewriteCond %{HTTP_ACCEPT} application/xhtml\+xml [OR]
+RewriteCond %{HTTP_USER_AGENT} ^Mozilla/.*
+RewriteRule ^$ @NAME@.html [L]
+
+# Rewrite rule to serve Turtle content from the vocabulary URI if requested
+RewriteCond %{HTTP_ACCEPT} text/turtle [OR]
+RewriteCond %{HTTP_ACCEPT} application/x-turtle
+RewriteRule ^$ @NAME@.ttl [L]
+
+# Serve HTML page by default
+RewriteRule ^$ @NAME@.html [L]
diff --git a/doc/index.php b/doc/index.php
deleted file mode 100644
index e6cdd10..0000000
--- a/doc/index.php
+++ /dev/null
@@ -1,60 +0,0 @@
-<?php
-# Content-type negotiation for LV2 specification bundles
-
-$rdfxml = accepts("application\/rdf\+xml");
-$turtle = accepts("application\/turtle");
-$x_turtle = accepts("application\/x-turtle");
-$text_turtle = accepts("text\/turtle");
-$json = accepts("application\/json");
-$html = accepts("text\/html");
-$xhtml = accepts("application\/xhtml\+xml");
-$text_plain = accepts("text\/plain");
-
-$name = basename($_SERVER['REQUEST_URI']);
-
-# Return Turtle ontology
-if ($turtle or $x_turtle or $text_turtle) {
- header("Content-Type: application/x-turtle");
- passthru("cat ./$name.ttl");
-
-# Return ontology translated into rdf+xml
-} else if ($rdfxml) {
- header("Content-Type: application/rdf+xml");
- passthru("~/bin/rapper -q -i turtle -o rdfxml-abbrev ./$name.ttl");
-
-} else if ($json) {
- header("Content-Type: application/json");
- passthru("~/bin/rapper -q -i turtle -o json ./$name.ttl");
-
-# Return HTML documentation
-} else if ($html or $xhtml) {
- if ($html) {
- header("Content-Type: text/html");
- } else {
- header("Content-Type: application/xhtml+xml");
- }
- $name = basename($_SERVER['REQUEST_URI']);
- passthru("cat ./$name.html | sed '
-s/<\/body>/<div style=\"font-size: smaller; color: gray; text-align: right; margin: 1ex;\">This document is content-negotiated. If you request it with <code>Accept: application\/x-turtle<\/code> you will get the description in Turtle. Also supported: <code>application\/rdf+xml<\/code>, <code>application\/json<\/code>, <code>text\/plain<\/code><\/div><\/body>/'");
-
-# Return NTriples (text/plain)
-} else if ($text_plain) {
- header("Content-Type: text/plain");
- passthru("~/bin/rapper -q -i turtle -o ntriples ./$name.ttl");
-
-# Return Turtle ontology by default
-} else {
- header("Content-Type: application/x-turtle");
- passthru("cat ./$name.ttl");
-}
-
-function accepts($type) {
- global $_SERVER;
- if (preg_match("/$type(;q=(\d+\.\d+))?/i", $_SERVER['HTTP_ACCEPT'], $matches)) {
- return isset($matches[2]) ? $matches[2] : 1;
- } else {
- return 0;
- }
-}
-
-?>
diff --git a/gendoc.py b/gendoc.py
index 2587e7b..a7d24b3 100755
--- a/gendoc.py
+++ b/gendoc.py
@@ -77,6 +77,16 @@ for cn in root.childNodes:
mafile, manchor))
bettertags.close()
+def subst_file(template, output, dict):
+ i = open(template, 'r')
+ o = open(output, 'w')
+ for line in i:
+ for key in dict:
+ line = line.replace(key, dict[key])
+ o.write(line)
+ i.close()
+ o.close()
+
print('** Generating core documentation')
lv2_outdir = os.path.join(out_base, 'lv2core')
@@ -84,7 +94,6 @@ os.mkdir(lv2_outdir)
shutil.copy('core.lv2/lv2.h', lv2_outdir)
shutil.copy('core.lv2/lv2.ttl', lv2_outdir)
shutil.copy('core.lv2/manifest.ttl', lv2_outdir)
-shutil.copy('doc/index.php', lv2_outdir)
oldcwd = os.getcwd()
os.chdir(lv2_outdir)
@@ -98,6 +107,9 @@ lv2specgen.save('lv2.html',
os.path.join('..', '..', '..', TAGFILE),
instances=True))
os.chdir(oldcwd)
+subst_file('doc/htaccess.in', '%s/lv2core/.htaccess' % out_base,
+ { '@NAME@': 'lv2core',
+ '@BASE@': '/ns/lv2core' })
footer = open('./lv2specgen/footer.html', 'r')
@@ -216,7 +228,9 @@ for dir in ['ext', 'extensions']:
row += '</tr>'
extensions.append(row)
- shutil.copy('doc/index.php', os.path.join(outdir, b + '.lv2', 'index.php'))
+ subst_file('doc/htaccess.in', '%s/%s.lv2/.htaccess' % (outdir, b),
+ { '@NAME@': b,
+ '@BASE@': '/ns/%s/%s' % (dir, b) })
# Remove .lv2 suffix from bundle name (to make URI resolvable)
os.rename(outdir + '/%s.lv2' % b, outdir + '/%s' % b)