<commit_before>#
# # Metal
#
# Our metalsmith build code.
#
path         = require 'path'
highlightjs  = require 'highlight.js'
marked       = require 'marked'
metalsmith   = require 'metalsmith'
collections  = require 'metalsmith-collections'
drafts       = require 'metalsmith-drafts'
excerpts     = require 'metalsmith-excerpts'
ignore       = require 'metalsmith-ignore'
markdown     = require 'metalsmith-markdown'
metadata     = require 'metalsmith-metadata'
permalinks   = require 'metalsmith-permalinks'
templates    = require 'metalsmith-templates'
aboutSchema  = require './plugins/about-schema'
authors      = require './plugins/authors'
defaultMeta  = require './plugins/defaultmeta'
descMeta     = require './plugins/descriptionMeta'
paginate     = require './plugins/paginate'
paginateTags = require './plugins/paginatetags'
popularApi   = require './plugins/popularapi'
moment       = require './plugins/moment'
feed         = require './plugins/feed'
filename     = require './plugins/filename'
newPage      = require './plugins/new-page'
recentApi    = require './plugins/recentapi'
redirects    = require './plugins/redirects'
series       = require './plugins/series'
snapshot     = require './plugins/snapshot'
tags         = require './plugins/tags'
titleify     = require './plugins/titleify'
videoScraper = require './plugins/video-scraper'


# Configure highlightjs with some language aliases
highlightjs.registerLanguage 'coffee', (hljs) ->
  hljs.getLanguage('coffeescript')


# Create a renderer instance which we'll use to modify the output of
# the markdown.
markedRenderer = new marked.Renderer()
markedRenderer.heading = (text, level) ->
  #  var escapedText = text.toLowerCase().replace(/[^\w]+/g, '-');
  #
  #  return '<h' + level + '><a name="' +
  #                escapedText +
  #                 '" class="anchor" href="#' +
  #                 escapedText +
  #                 '"><span class="header-link"></span></a>' +
  #                  text + '</h' + level + '>';
  link = text.toLowerCase().replace /[^\w]+/g, '-'
  "
  <h#{level} class='heading'>
    <a name='#{link}' class='anchor' href='##{link}'></a>
    #{text}
  </h#{level}>
  "

markedRenderer.blockquote = (quote) ->
  quoteTypes = ["good", "warning", "error"]
  quoteType = ""
  for _quoteType in quoteTypes
    seeking = "<p>type:#{_quoteType}\n"
    if quote.indexOf(seeking) == 0
      # Set the quoteType to the current _quoteType
      quoteType = _quoteType
      # Trim the seeking from the quote
      quote = "<p>#{quote[seeking.length...]}"
      break
  "
  <blockquote class=\"fa fa-check #{quoteType}\">
    #{quote}
  </blockquote>
  "


# ## build
#
# Build our metalsmith project. Exported as a module.
#
# - callback(err, files): A function which is given an error
#   or a list of files when metalsmith is done.
module.exports = build = (callback=->) ->
  metalsmith __dirname
    .source '..'
    .destination 'build'
    # Ignore files from ever entering the stream
    .ignore ['.agignore', '.gitignore', '.git', '.metalsmith', 'legacy']
    .clean false
    # Place before the ignore plugin that removes non-markdown
    # from the stream
    .use metadata
      tagNames: 'categories.yaml'
    # Filename creates meta information about the originalFilename.<commit_msg>Reimplemented quote types to support custom classes and multi-quotes<commit_after>#
# # Metal
#
# Our metalsmith build code.
#
path         = require 'path'
highlightjs  = require 'highlight.js'
marked       = require 'marked'
metalsmith   = require 'metalsmith'
collections  = require 'metalsmith-collections'
drafts       = require 'metalsmith-drafts'
excerpts     = require 'metalsmith-excerpts'
ignore       = require 'metalsmith-ignore'
markdown     = require 'metalsmith-markdown'
metadata     = require 'metalsmith-metadata'
permalinks   = require 'metalsmith-permalinks'
templates    = require 'metalsmith-templates'
aboutSchema  = require './plugins/about-schema'
authors      = require './plugins/authors'
defaultMeta  = require './plugins/defaultmeta'
descMeta     = require './plugins/descriptionMeta'
paginate     = require './plugins/paginate'
paginateTags = require './plugins/paginatetags'
popularApi   = require './plugins/popularapi'
moment       = require './plugins/moment'
feed         = require './plugins/feed'
filename     = require './plugins/filename'
newPage      = require './plugins/new-page'
recentApi    = require './plugins/recentapi'
redirects    = require './plugins/redirects'
series       = require './plugins/series'
snapshot     = require './plugins/snapshot'
tags         = require './plugins/tags'
titleify     = require './plugins/titleify'
videoScraper = require './plugins/video-scraper'


# Configure highlightjs with some language aliases
highlightjs.registerLanguage 'coffee', (hljs) ->
  hljs.getLanguage('coffeescript')


# Create a renderer instance which we'll use to modify the output of
# the markdown.
markedRenderer = new marked.Renderer()
markedRenderer.heading = (text, level) ->
  #  var escapedText = text.toLowerCase().replace(/[^\w]+/g, '-');
  #
  #  return '<h' + level + '><a name="' +
  #                escapedText +
  #                 '" class="anchor" href="#' +
  #                 escapedText +
  #                 '"><span class="header-link"></span></a>' +
  #                  text + '</h' + level + '>';
  link = text.toLowerCase().replace /[^\w]+/g, '-'
  "
  <h#{level} class='heading'>
    <a name='#{link}' class='anchor' href='##{link}'></a>
    #{text}
  </h#{level}>
  "

# In our version of blockquote, we're looking for `type:foo` strings
# and styling the blockquote based on that string.
#
# It's also worth noting that we're *only* looking at that string if
# it starts a paragraph on a line of it's own. This is mainly for
# implementation simplicity, but also helps provide a sane way to
# split up the markdown. If you want two blockquotes, add a newline to
# ensure a new paragraph.
markedRenderer.blockquote = (quote) ->
  quoteTypes =
    "good": "good fa fa-check-circle"
    "warning": "warning fa fa-info-circle"
    "error": "error fa fa-exclamation-circle"

  # Blocks is the final list of blockquotes that we're going to return
  blocks = []
  # Split the quote based on `<p>type:`, since we know that is what
  # starts any quote types. We can then iterate over it, with the
  # knowledge that each item in the array is a potentially blockquote
  for block, i in quote.split "<p>type:"
    # If block is empty, skip it. This means that <p>type: was at
    # the beginning of the quote, and we can ignore it
    continue if block == ""
    typeMatch = false
    classes = ""
    for quoteType, _classes of quoteTypes
      # If the blockquote starts with our type, we found it!
      if block.indexOf("#{quoteType}\n") == 0
        typeMatch = true
        classes = _classes
        # Remove the quoteType\n from the block. Eg,
        # `good\nfoo\nbar` becomes `foo\nbar`
        block = block[quoteType.length+1...]
        # Add back the <p> that we stole, but ignore the type, since
        # we don't want that in the final quote for matches
        block = "<p>" + block
    # If there was no match for any quoteType, then add back the
    # <p>type: that we stole
    # Note that the zero index (0) wasn't actually split on the type,
    # so make sure not to add type back.
    if not typeMatch and i != 0 then block = "<p>type:" + block
    console.log "[#{i}] Writing block: '#{block}'"
    # Now add our block to the final list
    blocks.push "
    <blockquote class=\"#{classes}\">
      #{block}
    </blockquote>
    "
  # And finally, return our blocks
  blocks.join '\n'


# ## build
#
# Build our metalsmith project. Exported as a module.
#
# - callback(err, files): A function which is given an error
#   or a list of files when metalsmith is done.
module.exports = build = (callback=->) ->
  metalsmith __dirname
    .source '..'
    .destination 'build'
    # Ignore files from ever entering the stream
    .ignore ['.agignore', '.gitignore', '.git', '.metalsmith', 'legacy']
    .clean false
    # Place before the ignore plugin that removes non-markdown
    # from the stream
    .use metadata
      tagNames: 'categories.yaml'
    # Filename creates meta information about the originalFilename.
{'fraction_non_alphanumeric': 0.12850102175742276, 'fraction_numerical': 0.0006010337780983291, 'mean_word_length': 2.950617283950617, 'pattern_counts': {'":': 3, '<': 36, '<?xml version=': 0, '>': 46, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4704608', 'n_tokens_mistral': 2516, 'n_tokens_neox': 2428, 'n_words': 797}