New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is possible get list of pages? #123
Comments
Hi @Simonini currently this isn't a feature of High Voltage. Can you explain the use case you are trying to achieve? |
Hi @harlow ! I would like output an html list of current pages. |
You could use Ruby to list all of the file in a directory. However... you'd still only have the paths of the files and not the meta-data (title, etc) from the pages. What is the use-case for this? Is it a sitemap? |
HI @harlow, same question here, in my case I want to do a sitemap in xml for a website. I just need the URL for every page to get a result like <url>
<loc>http://www.myawesomesite.com/about</loc>
<changefreq>weekly</changefreq>
<priority>1.00</priority>
</url>
... from (though) something like @static_pages.each do |page|
xml.url do
xml.loc "#{page_url}"
xml.changefreq("weekly")
xml.priority 0.9
end
end It's some way to do that? |
+1 |
Hi @davity you could write small class that will traverse the If you need some help writing the Ruby let me know. If it works as expected we could consider creating a PR for the HighVoltage gem. Maybe the interface would look like |
Hi @harlow, sorry for the delay, I was quite busy last week. ["about-this-site", "cookies", "more/your-rights", "more/even-more/about-us"] And then it will be easy to iterate over the array and get all the routes |
This would deal with the root of the pages directory. Dir.entries(Rails.root.join('app', 'views', 'pages')).map { |x| x.sub(/\.html\.[a-z]+$/,"") } |
def get_pages
pages = []
Dir.entries(Rails.root.join('app', 'views', 'pages')).each do |f|
matches = f.match(/\.html\.[a-zs]+$/)
if matches.nil?
next
end
filename = f.sub(matches[0], "")
title = filename.titleize
path = page_path(filename)
pages.push( { title: title, path: path } )
end
pages
end Returns: [{:title=>"About Us", :path=>"/pages/about-us"}, {:title=>"Address Book", :path=>"/pages/address-book"}] |
Thanks for posting some code @kim3er. Looks like the Hopefully this will be enough code to get everyone rolling along. Closing the issue. |
@harlow Would you still be open to a PR for this functionality, provided it was good quality and the interface you want? |
Would love to see a PR for this - we are generating sitemaps too. Thanks @kim3er for the snippet to do this for us, for now. And advance thanks to @bentoncreation for any PR submitted. [edit] I've taken the liberty of tidying up @kim3er's code into a drop-in module you can pop into your rails |
Is there a way to get a dynamic list of pages?
The text was updated successfully, but these errors were encountered: