Publishing Middleman's sitemap - sitemap

Middleman can show a sitemap under its config url when a local server is running. When publishing the static site to a CDN I cannot find anyway to access this sitemap, and I'd like to have it there for SEO purposes. I've assumed up to this point middleman includes the sitemap in the build, but I cannot find it now that I look. Assuming that's true, how can I publish the sitemap online?

While I'm a bit of a Middleman newbie, and haven't gotten around to adding a sitemap to my Middleman site, my friend uses the Middleman Search Engine Sitemap gem to generate a sitemap in his sites.
Another solution that I have seen is to use a Builder file to generate the sitemap:
Create a source file: source/sitemap.xml.builder.
xml.instruct!
xml.urlset 'xmlns' => "http://www.sitemaps.org/schemas/sitemap/0.9" do
sitemap.resources.select { |page| page.destination_path =~ /\.html/ && page.data.noindex != true }.each do |page|
xml.url do
xml.loc URI.join(settings.casper[:blog][:url], page.destination_path)
last_mod = if page.path.start_with?('articles/')
File.mtime(page.source_file).to_time
else
Time.now
end
xml.lastmod last_mod.iso8601
xml.changefreq page.data.changefreq || "monthly"
xml.priority page.data.priority || "0.5"
end
end
end

Related

Get Wordpress posts by tag in Ruby

We have a Wordpress instance with the XML-RPC API enabled and a Ruby on Rails website we want to display Wordpress posts on. I need to get posts by "tag". Looking at Rubypress it seems as though I have to wp.getPosts and parse out the correct ones. This is inefficient as we add new posts and have to keep updating.
Is there a way to get posts from a Wordpress instance via the API by tag?
Thank you.
We solved this with the wp_api_client gem and using the tags?slug=TAG endpoint. e.g.
require 'wp_api_client'
WpApiClient.configure do |api_client|
api_client.endpoint = "yourwordpress.com/wp-json/wp/v2"
api_client.basic_auth = {username: username, password: password}
end
client = WpApiClient.get_client
client.get("tags?slug=#{tag_you_want}").each do |tag|
client.get("posts?tags=#{tag.id}")
end

Jekyll site via Sinatra and Heroku - can't route to new posts

I created a 'Hello, World' app using Sinatra and then pushed to Heroku and all worked.
I've since created a basic Jekyll blog, and am trying to access it via Heroku using the following routes:
get '/?' do
file.read("_site/index.html")
end
get '/.*.*' do
file.read("_site/#{params[:splat]}")
end
not_found do
file.read("_site/error/index.html")
end
The route to the index works fine link to my site
but as soon as I click to the first post it always fails.
I have tried so many variations of different routes for the :splat and get, just can't seem to get it to work? Any ideas?
In the route that's failing, before the file.read statement, add warn "splat = #{params[:splat]}" and that will output the result to the terminal, and you can see what it's actually getting, e.g.
get '/.*.*' do
warn "splat = #{params[:splat]}"
file.read("_site/#{params[:splat]}")
end
You could also try using an absolute path to the files, though if you're getting the index page then it suggests it's not needed:
config do
set :statics, File.expand_path(File.join(settings.root, "_site"))
end
get '/.*.*' do
file.read( File.join settings.statics, params[:splat] )
end
Unless there's something else you were planning to use Sinatra's routes for, you could probably remove the Sinatra routes entirely and just make the "_site" folder the public_folder, and then Sinatra will do the serving of the static files for you:
config do
set :public_folder, File.expand_path(File.join(settings.root, "_site"))
end
# no more to do...

AWS to serve CSS images Sinatra

I am using the asset_sync gem to sync my assets to a S3 bucket. In production i want to use S3 and in development i want to use my local files. So i have setup the following along with a helper
environments/development.rb
configure :development do
set :asset_host, "/"
end
environments/production.rb
configure :production do
set :asset_host, "https://s3-eu-west-1.amazonaws.com/#{ENV['FOG_DIRECTORY']}"
end
helper
helpers do
def aws_asset( path )
File.join settings.asset_host, path
end
end
So in my views i can do this
<%= image_tag( aws_asset "/assets/images/wd.png") %>
Which will result in rendering that image from my local assets if in development or from my bucket when in production
So what if i want to render an image from within my main.css file, such as a background image? I cant do the below for example as its not an erb file
main.css
header{
background: #ffffff url('<%= aws_asset("/assets/images/bgwRpeat.png") %>') repeat-x;
}
So what can I do? Has anyone done this before
Thanks for any help anyone can offer
3 ways come to mind.
Precompile the assets
Before you deploy, precompile the assets and CSS. If you create a file called main.css.erb and then run it through ERB to produce main.css it'll have the right stuff inside. This would be my preference. There are lots of ways to precompile, I prefer Guard but YMMV.
Edit:
Lifted and twisted from the Guard::Erb docs
guard 'erb', :input => 'app/views/stylesheets/main.css.erb', :output => "public/assets/stylesheets/main.css" do
watch (%r{app/views/stylesheets/main.css.erb})
end
Something like that.
Create a route that then compiles the assets
This is similar to how you might use SASS templates with Sinatra (if you don't precompile them). Just do the same as above, set up a route for main.css, run the main.css.erb template through ERB and serve it. Add lots of caching.
Edit:
get "/assets/stylesheets/main.css" do
# remember to look at caching
erb :"stylesheets/main.css"
end
I started writing and I can't remember the 3rd :) In my defence, I've a terrible headache. Perhaps someone else will remember for me.

How to write ruby program that logins to a website

I have little experience in ruby language and I know it's a powerful language specifically in web programming. My questions is how can I write program that automatically log in to a website and download the daily news feeds. i.e. logging in to a forum website and downloading all the threads. Thnx
For tasks like these that simulate a web browser experience, I use the mechanize gem. It works like this:
require 'rubygems'
require 'mechanize'
www = Mechanize.new
www.get('http://your.site/path/to/login/page') do |login_page|
inside_page = login_page.form_with(:action => '/path/to/login/form/action') do |f|
f.form_username_element_name = "username"
f.form_password_element_name = "password"
end.click_button
# Do stuff with "inside_page", like navigate, scrape links, etc...
# See the mechanize docs for details
end

how to get request path in rails3

I am trying to do something similar that I saw in a code snippet for a project in rails prior to 3.0.
The code snippet was in environment.rb
config.after_initialize do
ActionController::Base.asset_host = Proc.new do |source, request|
if request.format == 'pdf'
"file://#{Rails.root.join('public')}"
end
end
how can I incorporate this code in rails ?
which file should it go in?
how do I gain access to the request path?
You don't need to do this for for the public folder. All files and folders in this directory can be accessed from anywhere.

Resources