Skip to content

Commit

Permalink
chore: separar multipage de html5
Browse files Browse the repository at this point in the history
  • Loading branch information
jesustorresdev committed Jul 17, 2023
1 parent e2f9782 commit 9e58091
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 70 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
bundle install
- name: Generar la documentación
run: bundle exec rake build:site build:pdf DOCUMENT_NAME=sistemas_operativos
run: bundle exec rake build:www build:pdf DOCUMENT_NAME=sistemas_operativos

- name: Publicar web
uses: JamesIves/github-pages-deploy-action@v4
Expand Down
56 changes: 2 additions & 54 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
require 'uri'
require 'webrick'

Rake.add_rakelib 'lib/tasks'

task :config do |t|
CONFIG[:html_multipage] = true
CONFIG[:asciidoctor_pdf_args] = [
'--require', 'asciidoctor-mathematical', '-a', 'mathematical-format=svg',
]
Expand All @@ -15,61 +13,11 @@ task :config do |t|
}
end

namespace :build do

desc 'Generar el sitio web donde se alojan los apuntes'
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

output_directory = File.dirname(Rake::Task['build:html'].prerequisites.first)
open(File.join(output_directory, 'index.html'), 'w') do |f|
f << <<~EOF
<!DOCTYPE HTML>
<html lang="es">
<head>
<meta charset="utf-8">
<meta http-equiv="refresh" content="0;url=main.html">
<link rel="canonical" href="main.html">
</head>
</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|
task :server, [:port] => 'build:www' do |t, args|
args.with_defaults(:port => CONFIG[:server_port])

website_root = File.dirname(Rake::Task['build:html'].prerequisites.first)
website_root = File.dirname(Rake::Task['build:www'].prerequisites.first)
server = WEBrick::HTTPServer.new :Port => args.port, :DocumentRoot => website_root

# Interceptar señales para detener el servidor.
Expand Down
2 changes: 0 additions & 2 deletions lib/task_helpers/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
:asciidoctor_epub_args,
:asciidoctor_html_args,
:asciidoctor_pdf_args,
:html_multipage,
:htmlproofer_opts,
:pandoc_docx_args,
:server_port,
Expand All @@ -18,7 +17,6 @@ def initialize()
asciidoctor_epub_args: [],
asciidoctor_html_args: [],
asciidoctor_pdf_args: [],
html_multipage: false,
htmlproofer_opts: {},
pandoc_docx_args: [],
server_port: 8080,
Expand Down
4 changes: 3 additions & 1 deletion lib/task_helpers/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def find_documents()
:docx => make_output_dirname(source_directory, "docx"),
:epub => make_output_dirname(source_directory, "epub"),
:html => make_output_dirname(source_directory, "html"),
:www => make_output_dirname(source_directory, "www"),
:pdf => make_output_dirname(source_directory, "pdf"),
}
{
Expand All @@ -50,7 +51,8 @@ def find_documents()
:docbook => File.join(output_directories[:docbook], get_output_filename(namespaces, "docbook")),
:docx => File.join(output_directories[:docx], get_output_filename(namespaces, "docx")),
:epub => File.join(output_directories[:epub], get_output_filename(namespaces, "epub")),
:html => File.join(output_directories[:html], "#{DEFAULT_OUTPUT_NAME}.html"),
:html => File.join(output_directories[:html], get_output_filename(namespaces, "html")),
:www => File.join(output_directories[:www], "#{DEFAULT_OUTPUT_NAME}.html"),
:pdf => File.join(output_directories[:pdf], get_output_filename(namespaces, "pdf")),
},
:docstats_pathname => File.join(source_directory, DOCUMENT_STATS_FILE),
Expand Down
13 changes: 1 addition & 12 deletions lib/tasks/build_html.rake
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,7 @@ Project::documents.each do |document|

file document[:output_pathnames][:html] => [*document[:dependencies], :config] do |t, args|
asciidoctor_args = CONFIG[:asciidoctor_args] + CONFIG[:asciidoctor_html_args]
if Utils::EnvVar.new('HTML_COMMENTS_ENABLED').to_boolean
asciidoctor_args += ['--attribute', 'comments_enabled=true']
end

backend_args = CONFIG[:html_multipage] ? [
'--backend', 'multipage_html5',
'--require', 'asciidoctor-multipage'
] : [
'--backend', 'html5'
]

sh "asciidoctor", *backend_args,
sh "asciidoctor", '--backend', 'html5',
'--require', './lib/time-admonition-block.rb',
'--require', './lib/autoxref-treeprocessor.rb',
'--attribute', "basedir=#{Project::PROJECT_DIRECTORY}",
Expand Down
89 changes: 89 additions & 0 deletions lib/tasks/build_www.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
require 'uri'

require_relative '../task_helpers/project.rb'
require_relative '../task_helpers/utils.rb'

Project::documents.each do |document|
namespace "#{document[:namespace_prefix]}build" do

desc "Generar la versión sitio web de '#{document[:pathname]}'"
task :www, [:site_root] => [
document[:output_pathnames][:www], :www_media_files, :www_index, :www_sitemap ] do |t, args|
end

file document[:output_pathnames][:www] => [*document[:dependencies], :config] do |t, args|
asciidoctor_args = CONFIG[:asciidoctor_args] + CONFIG[:asciidoctor_html_args]
if Utils::EnvVar.new('HTML_COMMENTS_ENABLED').to_boolean
asciidoctor_args += ['--attribute', 'comments_enabled=true']
end

sh "asciidoctor", '--backend', 'multipage_html5',
'--require', 'asciidoctor-multipage',
'--require', './lib/time-admonition-block.rb',
'--require', './lib/autoxref-treeprocessor.rb',
'--attribute', "basedir=#{Project::PROJECT_DIRECTORY}",
'--attribute', "outdir=#{document[:output_directories][:www]}",
*asciidoctor_args,
'--destination-dir', document[:output_directories][:www], t.prerequisites.first()
end

task :www_media_files do |t|
Utils.copy_files(document[:media_files], document[:output_directories][:www], document[:source_directory])
end

task :www_index do |t|
open(File.join(document[:output_directories][:www], 'index.html'), 'w') do |f|
f << <<~EOF
<!DOCTYPE HTML>
<html lang="es">
<head>
<meta charset="utf-8">
<meta http-equiv="refresh" content="0;url=main.html">
<link rel="canonical" href="main.html">
</head>
</html>
EOF
end
end

task :www_sitemap do |t, args|
args.with_defaults(:site_root => CONFIG[:site_root])

output_directory = document[:output_directories][:www]
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

if ! document[:namespace_prefix].empty?
namespace :build do

desc 'Generar la versión sitio web de todos los documentos del proyecto'
task :www => "#{document[:namespace_prefix]}build:www"

end
end
end

0 comments on commit 9e58091

Please sign in to comment.