null+****@clear*****
null+****@clear*****
2011年 5月 25日 (水) 15:49:56 JST
Kouhei Sutou 2011-05-25 06:49:56 +0000 (Wed, 25 May 2011)
New Revision: 39e1c670d13c21a9743c5cdfc0128ea42edf64ad
Log:
[doc] support Facebook in prepare.
Modified files:
doc/themes/groonga/layout.html
tools/prepare-sphinx-html.rb
Modified: doc/themes/groonga/layout.html (+0 -28)
===================================================================
--- doc/themes/groonga/layout.html 2011-05-25 06:38:02 +0000 (ef3043e)
+++ doc/themes/groonga/layout.html 2011-05-25 06:49:56 +0000 (2556e61)
@@ -10,29 +10,7 @@
{% extends "default/layout.html" %}
{% set favicon = "favicon.ico" %}
-{% block extraheader %}
- <meta property="fb:page_id" content="201193596592346" />
- <meta property="fb:admins" content="kouhei.sutou" />
- <meta property="og:type" content="product" />
- <meta property="og:image" content="http://groonga.org/images/groonga.png" />
- <meta property="og:site_name" content="groonga" />
- <script src="http://connect.facebook.net/ja_JP/all.js"></script>
-
- <script>
- window.fbAsyncInit = function() {
- FB.init({
- appId : null,
- status : true, // check login status
- cookie : true, // enable cookies to allow the server to access the session
- xfbml : true // parse XFBML
- });
- };
- </script>
- {{ super() }}
-{% endblock %}
-
{% block header %}
-<div id="fb-root"></div>
<div class="header">
<h1 class="title">
<a id="top-link" href="{{ pathto('index.html', 1) }}">
@@ -43,12 +21,6 @@
</a>
</h1>
- <div class="facebook-buttons">
- <fb:like href="http://www.facebook.com/pages/groonga/201193596592346"
- layout="standard"
- width="250"></fb:like>
- </div>
-
<div class="other-language-links">
<ul>
{%- if language != "en" %}
Modified: tools/prepare-sphinx-html.rb (+87 -23)
===================================================================
--- tools/prepare-sphinx-html.rb 2011-05-25 06:38:02 +0000 (172f5ff)
+++ tools/prepare-sphinx-html.rb 2011-05-25 06:49:56 +0000 (8995e0e)
@@ -7,66 +7,127 @@ end
require 'pathname'
-def fix_link(text, extension, locale)
- send("fix_#{extension}_link", text, locale)
+def fix_link(text, extension, language)
+ send("fix_#{extension}_link", text, language)
end
def fix_link_path(text)
text.gsub(/\b_(sources|static)\b/, '\1')
end
-def fix_locale_link(url, locale)
+def fix_language_link(url, language)
url.gsub(/\A((?:\.\.\/){2,})([a-z]{2})\/html\//) do
relative_base_path = $1
- link_locale = $2
+ link_language = $2
close_quote = $3
- if locale == "en"
+ if language == "en"
relative_base_path = relative_base_path.gsub(/\A\.\.\//, '')
end
- if link_locale != "en"
- relative_base_path += "#{link_locale}/"
+ if link_language != "en"
+ relative_base_path += "#{link_language}/"
end
"#{relative_base_path}docs/"
end
end
-def fix_html_link(html, locale)
+def fix_html_link(html, language)
html = html.gsub(/(href|src)="(.+?)"/) do
attribute = $1
link = $2
link = fix_link_path(link)
- link = fix_locale_link(link, locale)
+ link = fix_language_link(link, language)
"#{attribute}=\"#{link}\""
end
html.gsub(/(id="top-link" href=)"(.+?)"/) do
prefix = $1
- top_path = $2
- top_path = "." if top_path == "#"
- "#{prefix}\"#{top_path}/../\""
+ top_path = $2.gsub(/index\.html\z/, '../')
+ top_path = "./" if top_path == "#"
+ "#{prefix}\"#{top_path}../\""
end
end
-def fix_js_link(js, locale)
+def fix_js_link(js, language)
fix_link_path(js)
end
+LANGUAGE_TO_LOCALE = {
+ "ja" => "ja_JP",
+ "en" => "en_US",
+}
+
+def insert_facebook_html_header(html, language)
+ locale = LANGUAGE_TO_LOCALE[language]
+ raise "unknown locale for language #{language.inspect}" if locale.nil?
+ html.gsub(/<\/head>/) do
+ <<-HTML
+ <meta property="fb:page_id" content="201193596592346" />
+ <meta property="fb:admins" content="kouhei.sutou" />
+ <meta property="og:type" content="product" />
+ <meta property="og:image" content="http://groonga.org/images/groonga.png" />
+ <meta property="og:site_name" content="groonga" />
+ <script src="http://connect.facebook.net/#{locale}/all.js"></script>
+
+ <script>
+ window.fbAsyncInit = function() {
+ FB.init({
+ appId : null,
+ status : true, // check login status
+ cookie : true, // enable cookies to allow the server to access the session
+ xfbml : true // parse XFBML
+ });
+ };
+ </script>
+ </head>
+ HTML
+ end
+end
+
+def insert_facebook_html_fb_root(html)
+ html.gsub(/<body>/) do
+ <<-HTML
+ <body>
+ <div id="fb-root"></div>
+ HTML
+ end
+end
+
+def insert_facebook_html_buttons(html)
+ html.gsub(/(<div class="other-language-links">)/) do
+ <<-HTML
+ <div class="facebook-buttons">
+ <fb:like href="http://www.facebook.com/pages/groonga/201193596592346"
+ layout="standard"
+ width="250"></fb:like>
+ </div>
+ #{$1}
+ HTML
+ end
+end
+
+def insert_facebook_html(html, language)
+ html = insert_facebook_html_header(html, language)
+ html = insert_facebook_html_fb_root(html)
+ html = insert_facebook_html_buttons(html)
+ html
+end
+
source_dir, dest_dir = ARGV
source_dir = Pathname.new(source_dir)
dest_dir = Pathname.new(dest_dir)
-locale_dirs = []
+language_dirs = []
source_dir.each_entry do |top_level_path|
- locale_dirs << top_level_path if /\A[a-z]{2}\z/ =~ top_level_path.to_s
+ language_dirs << top_level_path if /\A[a-z]{2}\z/ =~ top_level_path.to_s
end
-locale_dirs.each do |locale_dir|
- locale = locale_dir.to_s
- locale_source_dir = source_dir + locale_dir + "html"
- locale_dest_dir = dest_dir + locale_dir
- locale_source_dir.find do |source_path|
- relative_path = source_path.relative_path_from(locale_source_dir)
- dest_path = locale_dest_dir + relative_path
+language_dirs.each do |language_dir|
+ language = language_dir.to_s
+ language_source_dir = source_dir + language_dir + "html"
+ language_dest_dir = dest_dir + language_dir
+ language_source_dir.find do |source_path|
+ relative_path = source_path.relative_path_from(language_source_dir)
+ dest_path = language_dest_dir + relative_path
if source_path.directory?
dest_path.mkpath
else
@@ -74,7 +135,10 @@ locale_dirs.each do |locale_dir|
when ".html", ".js"
content = source_path.read
extension = source_path.extname.gsub(/\A\./, '')
- content = fix_link(content, extension, locale)
+ content = fix_link(content, extension, language)
+ if extension == "html"
+ content = insert_facebook_html(content, language)
+ end
dest_path.open("wb") do |dest|
dest.print(content.strip)
end