app/controllers/discourse-media-wiki-import/import_controller.rb
def convert_wiki_links(html:, wiki_page_topic_map:)
      html_doc = Nokogiri::HTML::DocumentFragment.parse(html)

      html_doc.css('a:not([href^="http"])').each do |anchor|
        # skip any named anchor tags (used for article nav)
        next if anchor['name']

        # use href value or link text when not set
        title ||= anchor['href']
        title ||= anchor.content

        # find topic URL in mapping
        topic_url = wiki_page_topic_map[title]&.url

        anchor['href'] = topic_url
      end

      return html_doc.to_html()
    end
##
# Converts any empty article links to a wiki link that will handle redirects to the corresponding Discourse topic.
#
Converts any empty article links to a wiki link that will handle redirects to the corresponding Discourse topic.
Converts any empty article links to a wiki link that will handle redirects to the corresponding Discourse topic .
def convert_wiki_links(html:, wiki_page_topic_map:)
      html_doc = Nokogiri::HTML::DocumentFragment.parse(html)
      html_doc.css('a:not([href^="http"])').each do |anchor|
        next if anchor['name']
        title ||= anchor['href']
        title ||= anchor.content
        topic_url = wiki_page_topic_map[title]&.url
        anchor['href'] = topic_url
      end
      return html_doc.to_html()
    end
def convert_wiki_links ( html : , wiki_page_topic_map : ) html_doc = Nokogiri :: HTML :: DocumentFragment . parse ( html ) html_doc . css ( 'a:not([href^="http"])' ) . each do | anchor | next if anchor [ 'name' ] title ||= anchor [ 'href' ] title ||= anchor . content topic_url = wiki_page_topic_map [ title ] &. url anchor [ 'href' ] = topic_url end return html_doc . to_html ( ) end
Converts any empty article links to a wiki link that will handle redirects to the corresponding Discourse topic.
Converts any empty article links to a wiki link that will handle redirects to the corresponding Discourse topic .
# skip any named anchor tags (used for article nav) # use href value or link text when not set # find topic URL in mapping
html
wiki_page_topic_map