<commit_before># frozen_string_literal: true
#
# == OptionalModules namespace
#
module OptionalModules
  #
  # == SocialHelper
  #
  module SocialHelper
    include AssetsHelper
    include ERB::Util

    # SEO Meta tags for index pages (include Facebook and Twitter)
    #
    # * *Args*    :
    #   - +category+ -> category corresponding to the page
    #   - +background+ -> background picture for category
    #
    def seo_tag_index(category, background = nil)
      return false if category.nil?
      img = background.nil? ? nil : attachment_url(background.image, :medium)
      title_seo = title_seo_structure(category.menu_title)
      set_meta_tags title: category.menu_title,
                    description: sanitize_and_truncate(category.referencement_description),
                    keywords: category.referencement_keywords,
                    og: {
                      title: title_seo,
                      description: sanitize_and_truncate(category.referencement_description),
                      type: 'article',
                      url: category.menu_link(category.name, true),
                      image: img
                    },
                    twitter: {
                      card: 'summary_large_image',
                      site: Figaro.env.twitter_username,
                      creator: Figaro.env.twitter_username,
                      title: title_seo,
                      description: sanitize_and_truncate(category.referencement_description),
                      url: category.menu_link(category.name, true),
                      image: img
                    }
    end

    # SEO Meta tags for show pages (include Facebook and Twitter)
    #
    # * *Args*    :
    #   - +element+ -> object for which we want informations
    #
    def seo_tag_show(element)
      img = image_for_object(element)
      title_seo = title_seo_structure(element.title)
      url = element.decorate.show_page_link(true)
      desc = html_escape_once(sanitize_and_truncate(element.referencement_description))

      set_meta_tags title: element.title,
                    description: desc,
                    keywords: element.referencement_keywords,
                    og: {
                      type:  'article',
                      title: title_seo,
                      description: desc,
                      url:   url,
                      image: img
                    },
                    twitter: {
                      card: 'summary_large_image',
                      site: @setting.try(:twitter_username),
                      creator: @setting.try(:twitter_username),
                      title: title_seo,
                      description: desc,
                      url:   url,
                      image: img
                    }
    end

    def seo_tag_custom(title = '', description = '')
      desc_seo = html_escape_once(sanitize_and_truncate(description))

      set_meta_tags title: title,
                    description: desc_seo,
                    keywords: desc_seo.split(' ').join(',')
    end

    # Social share buttons links
    #
    # * *Args*    :
    # * *Returns* :
    #
    def social_share_buttons
      return nil if return_nil_for_social_share? || @asocial
      element = element_by_action
      t = element.try(:menu_title).nil? ? element.title : element.menu_title

      awesome_share_buttons(title_seo_structure(t),
                            desc: html_escape_once(element.referencement_description),
                            image: image_for_object(element),
                            via: @setting.try(:twitter_username),
                            popup: true)
    end

    private

    def awesome_share_buttons(title = '', opts = {})
      rel = opts[:rel]
      html = []<commit_msg>Return nil if social share element is nil<commit_after># frozen_string_literal: true
#
# == OptionalModules namespace
#
module OptionalModules
  #
  # == SocialHelper
  #
  module SocialHelper
    include AssetsHelper
    include ERB::Util

    # SEO Meta tags for index pages (include Facebook and Twitter)
    #
    # * *Args*    :
    #   - +category+ -> category corresponding to the page
    #   - +background+ -> background picture for category
    #
    def seo_tag_index(category, background = nil)
      return false if category.nil?
      img = background.nil? ? nil : attachment_url(background.image, :medium)
      title_seo = title_seo_structure(category.menu_title)
      set_meta_tags title: category.menu_title,
                    description: sanitize_and_truncate(category.referencement_description),
                    keywords: category.referencement_keywords,
                    og: {
                      title: title_seo,
                      description: sanitize_and_truncate(category.referencement_description),
                      type: 'article',
                      url: category.menu_link(category.name, true),
                      image: img
                    },
                    twitter: {
                      card: 'summary_large_image',
                      site: Figaro.env.twitter_username,
                      creator: Figaro.env.twitter_username,
                      title: title_seo,
                      description: sanitize_and_truncate(category.referencement_description),
                      url: category.menu_link(category.name, true),
                      image: img
                    }
    end

    # SEO Meta tags for show pages (include Facebook and Twitter)
    #
    # * *Args*    :
    #   - +element+ -> object for which we want informations
    #
    def seo_tag_show(element)
      img = image_for_object(element)
      title_seo = title_seo_structure(element.title)
      url = element.decorate.show_page_link(true)
      desc = html_escape_once(sanitize_and_truncate(element.referencement_description))

      set_meta_tags title: element.title,
                    description: desc,
                    keywords: element.referencement_keywords,
                    og: {
                      type:  'article',
                      title: title_seo,
                      description: desc,
                      url:   url,
                      image: img
                    },
                    twitter: {
                      card: 'summary_large_image',
                      site: @setting.try(:twitter_username),
                      creator: @setting.try(:twitter_username),
                      title: title_seo,
                      description: desc,
                      url:   url,
                      image: img
                    }
    end

    def seo_tag_custom(title = '', description = '')
      desc_seo = html_escape_once(sanitize_and_truncate(description))

      set_meta_tags title: title,
                    description: desc_seo,
                    keywords: desc_seo.split(' ').join(',')
    end

    # Social share buttons links
    #
    # * *Args*    :
    # * *Returns* :
    #
    def social_share_buttons
      return nil if return_nil_for_social_share? || @asocial
      element = element_by_action
      return nil if element.nil?
      t = element.try(:menu_title).nil? ? element.title : element.menu_title

      awesome_share_buttons(title_seo_structure(t),
                            desc: html_escape_once(element.referencement_description),
                            image: image_for_object(element),
                            via: @setting.try(:twitter_username),
                            popup: true)
    end

    private

    def awesome_share_buttons(title = '', opts = {})
      rel = opts[:rel]
      html = []
{'fraction_non_alphanumeric': 0.08028150658151961, 'fraction_numerical': 0.0, 'mean_word_length': 1.5760322255790533, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2757408', 'n_tokens_mistral': 2011, 'n_tokens_neox': 1912, 'n_words': 409}