summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2014-06-06 20:00:38 +0200
committerSamy Pessé <samypesse@gmail.com>2014-06-06 20:00:38 +0200
commit57491e3a8bbd20672fe80198f2bf8325c1f3e149 (patch)
tree82a923ce48ccb40a5060c1adb3be8df2ac4dd659
parentf7a442d297d3914b9e2bfea7709fd38e41a40e2a (diff)
downloadgitbook-57491e3a8bbd20672fe80198f2bf8325c1f3e149.zip
gitbook-57491e3a8bbd20672fe80198f2bf8325c1f3e149.tar.gz
gitbook-57491e3a8bbd20672fe80198f2bf8325c1f3e149.tar.bz2
Improve meta tags for books
-rw-r--r--lib/generate/index.js2
-rw-r--r--lib/generate/page/index.js22
-rw-r--r--lib/generate/site/index.js14
-rw-r--r--lib/generate/template.js47
-rwxr-xr-xtheme/templates/layout.html30
-rw-r--r--theme/templates/site.html18
6 files changed, 73 insertions, 60 deletions
diff --git a/lib/generate/index.js b/lib/generate/index.js
index adbcf26..6a319e8 100644
--- a/lib/generate/index.js
+++ b/lib/generate/index.js
@@ -1,9 +1,9 @@
var Q = require("q");
var _ = require("lodash");
var path = require("path");
-var swig = require('swig');
var tmp = require('tmp');
+var swig = require('./template');
var fs = require("./fs");
var parse = require("../parse");
var Plugin = require("./plugin");
diff --git a/lib/generate/page/index.js b/lib/generate/page/index.js
index d71229b..68fd334 100644
--- a/lib/generate/page/index.js
+++ b/lib/generate/page/index.js
@@ -2,32 +2,12 @@ var _ = require("lodash");
var util = require("util");
var path = require("path");
var Q = require("q");
-var swig = require('swig');
-var hljs = require('highlight.js');
+var swig = require("../template");
var fs = require("../fs");
var parse = require("../../parse");
var BaseGenerator = require("../site");
-// Swig filter: highlight coloration
-swig.setFilter('code', function(code, lang) {
- try {
- return hljs.highlight(lang, code).value;
- } catch(e) {
- return hljs.highlightAuto(code).value;
- }
-});
-
-// Convert a level into a deep level
-swig.setFilter('lvl', function(lvl) {
- return lvl.split(".").length;
-});
-
-// Join path
-swig.setFilter('pathJoin', function(base, _path) {
- return path.join(base, _path);
-});
-
/*
* This generator will generate a simple index.html which can be converted as a PDF
diff --git a/lib/generate/site/index.js b/lib/generate/site/index.js
index abbb9f0..51f8cae 100644
--- a/lib/generate/site/index.js
+++ b/lib/generate/site/index.js
@@ -2,7 +2,7 @@ var util = require("util");
var path = require("path");
var Q = require("q");
var _ = require("lodash");
-var swig = require('swig');
+var swig = require("../template");
var fs = require("../fs");
var parse = require("../../parse");
@@ -11,17 +11,7 @@ var links = require("../../utils/links");
var indexer = require('./search_indexer');
var Manifest = require('../manifest');
-// Swig filter for returning the count of lines in a code section
-swig.setFilter('lines', function(content) {
- return content.split('\n').length;
-});
-
-// Swig filter for returning a link to the associated html file of a markdown file
-swig.setFilter('mdLink', function(link) {
- var link = link.replace(".md", ".html");
- if (link == "README.html") link = "index.html";
- return link;
-});
+
var Generator = function() {
BaseGenerator.apply(this, arguments);
diff --git a/lib/generate/template.js b/lib/generate/template.js
new file mode 100644
index 0000000..a4ac4fd
--- /dev/null
+++ b/lib/generate/template.js
@@ -0,0 +1,47 @@
+var path = require("path");
+var swig = require('swig');
+var hljs = require('highlight.js');
+
+var pkg = require('../../package.json');
+
+swig.setDefaults({
+ locals: {
+ gitbook: {
+ version: pkg.version
+ }
+ }
+});
+
+// Swig filter for returning the count of lines in a code section
+swig.setFilter('lines', function(content) {
+ return content.split('\n').length;
+});
+
+// Swig filter for returning a link to the associated html file of a markdown file
+swig.setFilter('mdLink', function(link) {
+ var link = link.replace(".md", ".html");
+ if (link == "README.html") link = "index.html";
+ return link;
+});
+
+
+// Swig filter: highlight coloration
+swig.setFilter('code', function(code, lang) {
+ try {
+ return hljs.highlight(lang, code).value;
+ } catch(e) {
+ return hljs.highlightAuto(code).value;
+ }
+});
+
+// Convert a level into a deep level
+swig.setFilter('lvl', function(lvl) {
+ return lvl.split(".").length;
+});
+
+// Join path
+swig.setFilter('pathJoin', function(base, _path) {
+ return path.join(base, _path);
+});
+
+module.exports = swig;
diff --git a/theme/templates/layout.html b/theme/templates/layout.html
index 5f76e5e..cd4e3ab 100755
--- a/theme/templates/layout.html
+++ b/theme/templates/layout.html
@@ -1,38 +1,18 @@
<!DOCTYPE HTML>
<html lang="en-US" {% block htmlTag %}{% endblock %}>
{{ htmlSnippet("html:start")|default("") }}
- <head prefix="og: http://ogp.me/ns# book: http://ogp.me/ns/book#">
+ <head>
{{ htmlSnippet("head:start")|default("") }}
{% block head %}
<meta charset="UTF-8">
- <title>{% block title %} | {{ title }}{% endblock %}</title>
-
+ <title>{% block title %}{% endblock %}</title>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
- <meta name="robots" content="index, follow">
- <meta name="author" content="{{ githubAuthor }}">
- <meta name="description" content="{{ description }}">
- <meta name="keywords" content="gitbook,github" >
- <meta name="generator" content="www.gitbook.io">
-
- {% if progress.current.next and progress.current.next.path %}
- <link rel="next" href="{{ basePath }}/{{ progress.current.next.path|mdLink }}" />
- {% endif %}
- {% if progress.current.prev and progress.current.prev.path %}
- <link rel="prev" href="{{ basePath }}/{{ progress.current.prev.path|mdLink }}" />
- {% endif %}
-
- <meta property="og:title" content="{% block title %} | {{ title }}{% endblock %}">
- <meta property="og:site_name" content="{{ title }}">
- <meta property="og:type" content="book">
- <meta property="og:locale" content="en_US">
-
- <meta property="book:author" content="{{ githubHost }}{{ githubAuthor }}">
- <meta property="book:tag" content="GitBook">
-
+ <meta name="description" content="{% block description %}{% endblock %}">
+ <meta name="generator" content="GitBook {{ gitbook.version }}">
+ <meta name="HandheldFriendly" content="true"/>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
-
<link rel="shortcut icon" href="{{ staticBase }}/images/favicon.ico" type="image/x-icon">
{% endblock %}
{{ htmlSnippet("head:end")|default("") }}
diff --git a/theme/templates/site.html b/theme/templates/site.html
index b0a2ba4..607ffbf 100644
--- a/theme/templates/site.html
+++ b/theme/templates/site.html
@@ -1,7 +1,23 @@
{% extends "layout.html" %}
{% block htmlTag %}{% if options.cache !== false %}manifest="{{ basePath }}/manifest.appcache"{% endif %}{% endblock %}
-{% block title %}{{ progress.current.title }}{% parent %}{% endblock %}
+
+{% block title %}{{ progress.current.title }} | {{ title }}{% endblock %}
+{% block description %}{% if progress.current.level == "0" %}{{ description }}{% endif %}{% endblock %}
+
+{% block head %}
+ {% parent %}
+ {% if githubAuthor %}
+ <meta name="author" content="{{ githubAuthor }}">
+ {% endif %}
+ {% if progress.current.next and progress.current.next.path %}
+ <link rel="next" href="{{ basePath }}/{{ progress.current.next.path|mdLink }}" />
+ {% endif %}
+ {% if progress.current.prev and progress.current.prev.path %}
+ <link rel="prev" href="{{ basePath }}/{{ progress.current.prev.path|mdLink }}" />
+ {% endif %}
+{% endblock %}
+
{% block content %}
<div class="book" {% if githubId %}data-github="{{ githubId }}"{% endif %} data-level="{{ progress.current.level }}" data-basepath="{{ basePath }}" data-revision="{{ revision }}">
{% include "includes/book/header.html" %}