From e2f9782b7b6b4c2004df1f42af8f857eb3c92906 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Torres?= Date: Mon, 17 Jul 2023 18:58:00 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20generaci=C3=B3n=20autom=C3=A1tica=20del?= =?UTF-8?q?=20sitemap.xml?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Rakefile | 32 +++++++++++++++++++++++-- lib/task_helpers/config.rb | 49 +++++++++++++++++++++----------------- 2 files changed, 57 insertions(+), 24 deletions(-) diff --git a/Rakefile b/Rakefile index 5a568c0..2a8bf2b 100644 --- a/Rakefile +++ b/Rakefile @@ -1,3 +1,4 @@ +require 'uri' require 'webrick' Rake.add_rakelib 'lib/tasks' @@ -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 @@ -34,12 +37,37 @@ namespace :build do EOF end + open(File.join(output_directory, 'sitemap.xml'), 'w') do |f| + f << <<~EOF + + + EOF + + now = Time.now.iso8601 + Dir.glob('*.html', base: output_directory).each do |filename| + f << <<~EOF + + #{URI.join(args.site_root, URI.encode_www_form_component(filename))} + #{now} + #{filename == 'main.html' ? 1.0 : 0.5} + + EOF + end + + f << <<~EOF + + 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 diff --git a/lib/task_helpers/config.rb b/lib/task_helpers/config.rb index 3380e11..be12def 100644 --- a/lib/task_helpers/config.rb +++ b/lib/task_helpers/config.rb @@ -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() \ No newline at end of file