Set up assets for S3/CloudFront CDN

This commit is contained in:
Jonathan Rudenberg 2012-10-27 19:55:03 -04:00
parent 7ff4d0a1bb
commit 019ad29a7f
12 changed files with 93 additions and 10 deletions

View file

@ -13,7 +13,7 @@ gem 'slim'
gem 'rainpress' gem 'rainpress'
gem 'nokogiri' gem 'nokogiri'
gem 'adsf' gem 'adsf'
gem 'builder'
gem 'tent-schemas', :git => 'git://github.com/tent/tent-schemas.git', :branch => 'master' gem 'tent-schemas', :git => 'git://github.com/tent/tent-schemas.git', :branch => 'master'
gem 'pygments.rb' gem 'pygments.rb'
gem 'fssm', :groups => :development gem 'fssm', :groups => :development
gem 'asset_sync', :git => 'git://github.com/titanous/asset_sync.git', :branch => 'fix-mime'

View file

@ -6,24 +6,56 @@ GIT
tent-schemas (0.0.1) tent-schemas (0.0.1)
json-schema json-schema
GIT
remote: git://github.com/titanous/asset_sync.git
revision: 64f86044921b7029cf3be673a1920aa7fdfe8604
branch: fix-mime
specs:
asset_sync (0.5.0)
activemodel
fog
GEM GEM
remote: http://rubygems.org/ remote: http://rubygems.org/
specs: specs:
activemodel (3.2.8)
activesupport (= 3.2.8)
builder (~> 3.0.0)
activesupport (3.2.8)
i18n (~> 0.6)
multi_json (~> 1.0)
adsf (1.1.1) adsf (1.1.1)
rack (>= 1.0.0) rack (>= 1.0.0)
builder (3.1.4) builder (3.0.4)
clogger (1.1.0) clogger (1.1.0)
rack (> 0.9) rack (> 0.9)
colored (1.2) colored (1.2)
cri (2.3.0) cri (2.3.0)
colored (>= 1.2) colored (>= 1.2)
excon (0.16.7)
fog (1.6.0)
builder
excon (~> 0.14)
formatador (~> 0.2.0)
mime-types
multi_json (~> 1.0)
net-scp (~> 1.0.4)
net-ssh (>= 2.1.3)
nokogiri (~> 1.5.0)
ruby-hmac
formatador (0.2.4)
fssm (0.2.9) fssm (0.2.9)
i18n (0.6.1)
json-schema (1.0.10) json-schema (1.0.10)
mime-types (1.19) mime-types (1.19)
multi_json (1.3.6)
nanoc (3.4.1) nanoc (3.4.1)
cri (~> 2.2) cri (~> 2.2)
nanoc-cachebuster (0.3.1) nanoc-cachebuster (0.3.1)
nanoc (>= 3.3.0) nanoc (>= 3.3.0)
net-scp (1.0.4)
net-ssh (>= 1.99.1)
net-ssh (2.6.1)
nokogiri (1.5.5) nokogiri (1.5.5)
posix-spawn (0.3.6) posix-spawn (0.3.6)
puma (1.6.3) puma (1.6.3)
@ -35,6 +67,7 @@ GEM
rack-rewrite (1.3.0) rack-rewrite (1.3.0)
rainpress (1.0) rainpress (1.0)
redcarpet (2.2.2) redcarpet (2.2.2)
ruby-hmac (0.4.0)
slim (1.3.3) slim (1.3.3)
temple (~> 0.5.5) temple (~> 0.5.5)
tilt (~> 1.3.3) tilt (~> 1.3.3)
@ -47,7 +80,7 @@ PLATFORMS
DEPENDENCIES DEPENDENCIES
adsf adsf
builder asset_sync!
clogger clogger
fssm fssm
mime-types mime-types

12
Rakefile Normal file
View file

@ -0,0 +1,12 @@
require 'bundler/setup'
task :gzip_assets do
Dir['output/assets/**/*.*'].reject { |f| f =~ /\.gz\z/ }.each do |f|
sh "gzip -c #{f} > #{f}.gz" unless File.exist?("#{f}.gz")
end
end
task :deploy_assets => :gzip_assets do
require './config/asset_sync'
AssetSync.sync
end

1
Rules
View file

@ -40,6 +40,7 @@ compile '*' do
when 'md' when 'md'
filter :schema_table filter :schema_table
filter :api_example filter :api_example
filter :erb
filter :redcarpet, renderer: MarkdownHTML, options: { filter :redcarpet, renderer: MarkdownHTML, options: {
fenced_code_blocks: true, fenced_code_blocks: true,
no_intra_emphasis: true, no_intra_emphasis: true,

View file

@ -85,6 +85,7 @@ base_url: http://tent.io
title: Tent title: Tent
author_name: Tent author_name: Tent
author_uri: http://tent.io author_uri: http://tent.io
cdn_url: https://d31dxsia6hg3x2.cloudfront.net
# Configure the robots.txt file for this site. # Configure the robots.txt file for this site.
# Setting 'default' to true-ish will use sensible defaults. If you # Setting 'default' to true-ish will use sensible defaults. If you

13
config/asset_sync.rb Normal file
View file

@ -0,0 +1,13 @@
require 'asset_sync'
require 'mime/types'
AssetSync.configure do |config|
config.fog_provider = 'AWS'
config.fog_directory = ENV['S3_BUCKET']
config.aws_access_key_id = ENV['AWS_ACCESS_KEY_ID']
config.aws_secret_access_key = ENV['AWS_SECRET_ACCESS_KEY']
config.prefix = "assets"
config.public_path = Pathname("./output")
config.gzip_compression = true
config.always_upload = %w( manifest.json )
end

View file

@ -29,10 +29,10 @@ Tent servers maintain relationships between users and manage apps. Users create
With Tent, your relationships and data are all in one place that you control. on centralized services, your data and relationships are fragmented across multiple apps and networks. They can be difficult to export, and information about you is often sold. Like email, Tent lets you take your data and relationships with you when you change providers With Tent, your relationships and data are all in one place that you control. on centralized services, your data and relationships are fragmented across multiple apps and networks. They can be difficult to export, and information about you is often sold. Like email, Tent lets you take your data and relationships with you when you change providers
#### How Tent Works #### How Tent Works
![diagram](/assets/images/tent_diagram.png) ![diagram](<%= image_url('tent_diagram.png') %>)
#### How Other Services Work #### How Other Services Work
![diagram](/assets/images/other_services.png) ![diagram](<%= image_url('other_services.png') %>)
### How can I use Tent? ### How can I use Tent?

View file

@ -88,4 +88,4 @@ https://cloudmir.com/ (Lindsay) and https://titanous.com (Jonathan) are both fol
6. Lindsay, Jonathan, and Jesse can each read, reply to, repost, or ignore the post as they wish. 6. Lindsay, Jonathan, and Jesse can each read, reply to, repost, or ignore the post as they wish.
![diagram](/assets/images/diagram.png) ![diagram](<%= image_url('diagram.png') %>)

View file

@ -2,7 +2,7 @@ h1.intro
strong Tent strong Tent
| is a protocol for distributed social networking and personal data storage. | is a protocol for distributed social networking and personal data storage.
img.responsive#arrows src="/assets/images/arrows_top.png" img.responsive#arrows src=image_url('arrows_top.png')
.feature .feature
h2 Communicate h2 Communicate

View file

@ -1,8 +1,8 @@
meta name="viewport" content='width=device-width, initial-scale=1.0' meta name="viewport" content='width=device-width, initial-scale=1.0'
title = "#{@item[:title] + ' · ' if @item[:title]}Tent - the decentralized social web" title = "#{@item[:title] + ' · ' if @item[:title]}Tent - the decentralized social web"
link href='/assets/css/bootstrap.css' rel='stylesheet' type='text/css' media='screen' link href=asset_url('bootstrap.css') rel='stylesheet' type='text/css' media='screen'
link href='/assets/css/bootstrap-responsive.css' rel='stylesheet' type='text/css' media='screen' link href=asset_url('bootstrap-responsive.css') rel='stylesheet' type='text/css' media='screen'
link href='/assets/css/style.css' rel='stylesheet' type='text/css' media='screen' link href=asset_url('style.css') rel='stylesheet' type='text/css' media='screen'
link rel='alternate' type='application/atom+xml' title='Atom feed' href="/blog.xml" link rel='alternate' type='application/atom+xml' title='Atom feed' href="/blog.xml"
javascript: javascript:
var _gaq = _gaq || []; var _gaq = _gaq || [];

22
lib/asset_url.rb Normal file
View file

@ -0,0 +1,22 @@
module Nanoc3::Helpers::AssetURL
def asset_url(path, options = {})
name, extension = path.match(/([^.]+).(.+)$/).to_a[1..-1]
extensions = extension.split('.')
asset_dir = options[:asset_dir] || extensions.first
filename = "content/assets/#{asset_dir}/#{name}.#{extension}"
fp = fingerprint(filename)
path = "/assets/#{asset_dir}/#{name}#{fp}.#{extensions[0..extensions.size-2].join('.')}"
if ENV['USE_CDN']
@site.config[:cdn_url] + path
else
path
end
end
def image_url(path)
asset_url(path, :asset_dir => 'images')
end
end

View file

@ -8,5 +8,6 @@ include Nanoc3::Helpers::Blogging
include Nanoc3::Helpers::Filtering include Nanoc3::Helpers::Filtering
include Nanoc3::Helpers::LinkTo include Nanoc3::Helpers::LinkTo
include Nanoc3::Helpers::CacheBusting include Nanoc3::Helpers::CacheBusting
include Nanoc3::Helpers::AssetURL
Slim::Engine.set_default_options pretty: true Slim::Engine.set_default_options pretty: true