Skip to content

Commit

Permalink
feat: generación automática del sitemap.xml
Browse files Browse the repository at this point in the history
  • Loading branch information
jesustorresdev committed Jul 17, 2023
1 parent 3603bb9 commit e2f9782
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 24 deletions.
32 changes: 30 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'uri'
require 'webrick'

Rake.add_rakelib 'lib/tasks'
Expand All @@ -17,7 +18,9 @@ end
namespace :build do

desc 'Generar el sitio web donde se alojan los apuntes'
task :site do
task :site, [:site_root] do |t, args|
args.with_defaults(:site_root => CONFIG[:site_root])

#ENV['HTML_COMMENTS_ENABLED'] = '1'
Rake::Task['build:html'].invoke

Expand All @@ -34,12 +37,37 @@ namespace :build do
</html>
EOF
end
open(File.join(output_directory, 'sitemap.xml'), 'w') do |f|
f << <<~EOF
<?xml version="1.0" encoding="UTF-8"?>
<urlset
xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
EOF

now = Time.now.iso8601
Dir.glob('*.html', base: output_directory).each do |filename|
f << <<~EOF
<url>
<loc>#{URI.join(args.site_root, URI.encode_www_form_component(filename))}</loc>
<lastmod>#{now}</lastmod>
<priority>#{filename == 'main.html' ? 1.0 : 0.5}</priority>
</url>
EOF
end

f << <<~EOF
</urlset>
EOF
end
end
end

desc 'Iniciar el servidor web de desarrollo'
task :server, [:port] => 'build:site' do |t, args|
args.with_defaults(:port => 8080)
args.with_defaults(:port => CONFIG[:server_port])

website_root = File.dirname(Rake::Task['build:html'].prerequisites.first)
server = WEBrick::HTTPServer.new :Port => args.port, :DocumentRoot => website_root
Expand Down
49 changes: 27 additions & 22 deletions lib/task_helpers/config.rb
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
Struct.new('Config',
:html_multipage,
:asciidoctor_args,
:asciidoctor_docbook_args,
:asciidoctor_epub_args,
:asciidoctor_html_args,
:asciidoctor_pdf_args,
:htmlproofer_opts,
:pandoc_docx_args,
keyword_init: true) do
def initialize()
default_values = {
html_multipage: false,
asciidoctor_args: [],
asciidoctor_docbook_args: [],
asciidoctor_epub_args: [],
asciidoctor_html_args: [],
asciidoctor_pdf_args: [],
htmlproofer_opts: {},
pandoc_docx_args: []
}
super(default_values)
end
:asciidoctor_args,
:asciidoctor_docbook_args,
:asciidoctor_epub_args,
:asciidoctor_html_args,
:asciidoctor_pdf_args,
:html_multipage,
:htmlproofer_opts,
:pandoc_docx_args,
:server_port,
:site_root,
keyword_init: true) do

def initialize()
default_values = {
asciidoctor_args: [],
asciidoctor_docbook_args: [],
asciidoctor_epub_args: [],
asciidoctor_html_args: [],
asciidoctor_pdf_args: [],
html_multipage: false,
htmlproofer_opts: {},
pandoc_docx_args: [],
server_port: 8080,
site_root: 'http://localhost/'
}
super(default_values)
end
end

CONFIG = Struct::Config.new()

0 comments on commit e2f9782

Please sign in to comment.