dynamic_sitemaps icon indicating copy to clipboard operation
dynamic_sitemaps copied to clipboard

And heroku?

Open descovi opened this issue 10 years ago • 15 comments

Heroku file system prevent creation of static files. How can i use dynamic_sitemaps?

descovi avatar Sep 16 '13 15:09 descovi

I don't know – haven't used Heroku. Any ideas?

lassebunk avatar Sep 16 '13 16:09 lassebunk

+1

tayeke avatar Dec 06 '13 21:12 tayeke

Any ideas?

lassebunk avatar Dec 06 '13 22:12 lassebunk

I'm writing this custom rake task right now to send my sitemap to s3, but in the ping part of the dynamic sitemap generator you'd need to point to the s3 route. Oh and the config for the generator points to tmp directory.

namespace :sitemap do
desc "Generate dynamic sitemap then push to S3"
task :update => :environment do
    Rake::Task["sitemap:generate"].execute
    s3 = AWS::S3.new(access_key_id: ENV['AWS_ACCESS_KEY'],secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'])
    s3.buckets['mommychannel-sitemaps'].objects['sitemap.xml'].write(data: File.open(Rails.root.join('tmp','sitemaps','sitemap.xml')), acl: :public_read)
end
end

DynamicSitemaps.configure do |config|
   config.path = Rails.root.join("tmp")
end

Added heroku scheduler to run once a day.

tayeke avatar Dec 07 '13 03:12 tayeke

That sounds like a good solution. Would Google index the sitemap if it's not on the same server/host as the website? Thanks.

lassebunk avatar Dec 07 '13 09:12 lassebunk

It is supposed to if you use robots.txt. However I couldn't submit it manually without same host so I made a route that loads the file contents from S3. On Dec 7, 2013 1:08 AM, "Lasse Bunk" [email protected] wrote:

That sounds like a good solution. Would Google index the sitemap if it's not on the same server/host as the website? Thanks.

— Reply to this email directly or view it on GitHubhttps://github.com/lassebunk/dynamic_sitemaps/issues/15#issuecomment-30051039 .

tayeke avatar Dec 07 '13 16:12 tayeke

So your suggestion is to implement that in the plugin, so that it loads the file contents from S3 and serves that? Would this be plausible for big files? Thanks.

lassebunk avatar Dec 07 '13 22:12 lassebunk

I did not implement it into the gem, I just am using that rake task for getting around read-only file systems. My site generated about 1060 unique links, so I think it would work alright for most sites... On Dec 7, 2013 2:10 PM, "Lasse Bunk" [email protected] wrote:

So your suggestion is to implement that in the plugin, so that it loads the file contents from S3 and serves that? Would this be plausible for big files? Thanks.

— Reply to this email directly or view it on GitHubhttps://github.com/lassebunk/dynamic_sitemaps/issues/15#issuecomment-30066251 .

tayeke avatar Dec 08 '13 00:12 tayeke

I forked this gem to support store sitemaps at database or AWS.

ASAP I will do a pull request, i'm only waiting to have time to write some tests

This fork is available at: http://github.com/efqdalton/dynamic_sitemaps

And the branch with this feature is named adds-custom-storages

If someone wants to write those tests… it should be great!

efqdalton avatar Feb 25 '14 17:02 efqdalton

Thanks – looking forward to that! :)

On 25 Feb 2014 at 18:54:39, Dalton ([email protected]) wrote:

I forked this gem to support store sitemaps at database or AWS.

ASAP I will do a pull request, i'm only waiting to have time to write some tests

This fork is available at: http://github.com/efqdalton/dynamic_sitemaps

And the branch with this feature is named adds-custom-storages

If someone wants to write those tests… it should be great!

— Reply to this email directly or view it on GitHub.

lassebunk avatar Feb 26 '14 10:02 lassebunk

@efqdalton I would love to use your fork - any chance you could provide some pointers on how to use it please?

robbieshepherd avatar Nov 09 '14 01:11 robbieshepherd

I'm in such a rush this year, and I didn't have time to organize it...

So, if someone could finish that, it would be nice! Im using it in production on this site kuadro.com.br, but most of glue code is written in the app, using database as persistence, so it works.

On my fork, exists a branch called adds-custom-storage, use this branch.

So at config file you have to put this:

DynamicSitemaps.configure do |config|
  config.storage = DynamicSitemaps::DatabaseStorage
end

And add a migration like that to create Sitemap model:

class CreateSitemaps < ActiveRecord::Migration
  def change
    create_table :sitemaps do |t|
      t.string :path, null: false
      t.text :content
    end

    add_index :sitemaps, :path, unique: true
  end
end

And there is a a Job on Sidekiq squeduler that calls, once a day, this:

DynamicSitemaps.generate_sitemap

Now explaining better, to provide pointers to someone who wants to finish it:

As you could see, I created an abstract class Storage, and I added "3" implementations: DatabaseStorage, LocalStorage and S3Storage.

But don't be so happy, S3Storage is not working, I just started to write it, and not finished, since I started using DatabaseStorage, and it's working well... sorry...

One more problem, as you could see, the last change that I made to this branch was at Feb 25, so if someone finish it, it would be nice to rebase it...

So, I hope that I could help writing this, ask if there is more doubts, maybe I forgot something... 8 months is a long time to remember all details of a almost finished code.

dalthon avatar Nov 09 '14 09:11 dalthon

https://github.com/kjvarga/sitemap_generator could be used as an example of how to hook up S3 storage.

brandoncc avatar Jan 11 '15 07:01 brandoncc

@tayeke - Are your environment variables loaded fine when you run a rake task? I'm having trouble loading the values from my .env file.

The code works fine with string literals.

http://stackoverflow.com/questions/29585431/env-variables-not-loaded-when-invoked-in-rake-task

I'm using Mac Yosemite, Foreman and Unicorn. My .env file has the right keys.

sergiotapia avatar Apr 12 '15 02:04 sergiotapia

For anyone in here wondering, on Heroku the env variables will be loaded fine when running something like heroku run rake sitemaps:update. Locally however, you need to use something like Figaro.

sergiotapia avatar May 07 '15 16:05 sergiotapia