Module: Jekyll::VitePressTheme::CopyPage
- Defined in:
- lib/jekyll/vitepress_theme/hooks.rb
Class Method Summary collapse
- .enabled?(item) ⇒ Boolean
- .leading_h1?(markdown) ⇒ Boolean
- .liquid_render_info(item, payload) ⇒ Object
- .page_enabled?(item) ⇒ Boolean
- .resolved_markdown(item, payload) ⇒ Object
- .site_enabled?(site) ⇒ Boolean
- .with_title(markdown, title) ⇒ Object
Class Method Details
.enabled?(item) ⇒ Boolean
460 461 462 |
# File 'lib/jekyll/vitepress_theme/hooks.rb', line 460 def enabled?(item) site_enabled?(item.site) && page_enabled?(item) end |
.leading_h1?(markdown) ⇒ Boolean
504 505 506 507 508 509 510 511 512 513 |
# File 'lib/jekyll/vitepress_theme/hooks.rb', line 504 def leading_h1?(markdown) return false if markdown.nil? stripped = markdown.lstrip return false if stripped.empty? stripped.match?(/\A#\s+\S/) || stripped.match?(/\A<h1(?:\s|>)/i) || stripped.match?(/\A[^\n]+\n=+\s*(?:\n|$)/) end |
.liquid_render_info(item, payload) ⇒ Object
488 489 490 491 492 493 494 495 496 |
# File 'lib/jekyll/vitepress_theme/hooks.rb', line 488 def liquid_render_info(item, payload) = item.site.config['liquid'] || {} { registers: { site: item.site, page: payload['page'] }, strict_filters: ['strict_filters'], strict_variables: ['strict_variables'] } end |
.page_enabled?(item) ⇒ Boolean
471 472 473 474 475 |
# File 'lib/jekyll/vitepress_theme/hooks.rb', line 471 def page_enabled?(item) page_theme = item.data['jekyll_vitepress'] page_theme != false && !(page_theme.is_a?(Hash) && page_theme['copy_page'] == false) end |
.resolved_markdown(item, payload) ⇒ Object
477 478 479 480 481 482 483 484 485 486 |
# File 'lib/jekyll/vitepress_theme/hooks.rb', line 477 def resolved_markdown(item, payload) raw = item.content.to_s return raw unless item.respond_to?(:render_with_liquid?) && item.render_with_liquid? item.renderer.render_liquid(raw, payload, liquid_render_info(item, payload), item.path) rescue StandardError => e relative_path = item.respond_to?(:relative_path) ? item.relative_path : item.path Jekyll.logger.warn('jekyll-vitepress-theme', "Copy page markdown capture failed for #{relative_path}: #{e.}") raw end |
.site_enabled?(site) ⇒ Boolean
464 465 466 467 468 469 |
# File 'lib/jekyll/vitepress_theme/hooks.rb', line 464 def site_enabled?(site) theme_config = site.config['jekyll_vitepress'] copy_page = theme_config['copy_page'] if theme_config.is_a?(Hash) !(copy_page.is_a?(Hash) && copy_page['enabled'] == false) end |
.with_title(markdown, title) ⇒ Object
498 499 500 501 502 |
# File 'lib/jekyll/vitepress_theme/hooks.rb', line 498 def with_title(markdown, title) return markdown if markdown.to_s.empty? || title.to_s.empty? || leading_h1?(markdown) "# #{title}\n\n#{markdown}" end |