<commit_before>-#=current_page.inspect
=#locals
=#current_page.locals
=#current_page.data
=#current_page.request

- content_for :head do
  = stylesheet_link_tag "lib/admin"

:ruby
  arg = request['params']
  filter = arg['filter']

  articles_filtered = if arg.empty?
      page_articles
    else
      current_list = page_articles
      tokens = filter.split(/ /)
      #tokens = filter.class == "string" ? [filter] : filter.map { |s| s.gsub /^['"]|['"]$/, '' }

      tokens.each do |token|
        current_list.select! {|a| a.body.downcase.match token.downcase}
      end

      current_list
    end


%form.form.form-horizontal.newpost#newpost{action: "/admin/newpost", method: "post"}
  .col-sm-7
    %input.title.form-control{name: "title", placeholder: "Post title", autocomplete: "off"}
    .helpertip
      Please enter a title for your new blog post.

  .col-sm-3
    %select.form-control{name: "author"}
      - data.authors.sort_by {|n, d| author_name n}.each do |nick, data|
        - if nick == ENV['USER']
          %option{value: nick, selected: true}= author_name nick
        - else
          %option{value: nick}= author_name nick

  .col-sm-s
    %button#create-post-action.btn.btn-primary.col-sm-2
      Create post

%hr

%form.form.form-horizontal.filterform#filterform{action: "/admin/", method: "post"}
  .filter-wrap.col-sm-12
    %input.form-control.col-sm-11#filterbox{name: "filter", value: filter, placeholder: "Search all posts", autocomplete: "off"}

    %button.btn.clearer#filterclear
      ×

    %noscript
      %button.btn.btn-primary.col-sm-1 Filter


%table.articles.blog-admin#articlelist
  - articles_filtered.each do |article|

    - post_date = article.date.strftime("%F")
    - post_slug = article.slug

    %tr.article{class: " #{article.published? ? 'published' : 'draft'}"}

      %td.published
        - unless article.published?
          %i.draft-icon{title: "Draft"}

      %td
        .title
          =link_to article.title, "/admin/edit?date=#{post_date}&slug=#{post_slug}", {style: "display: block", title: "Edit article"}

        .meta
          %span.wordcount
            - wordcount = Nokogiri::HTML(article.body).text.scan(/[\w]+/).size
            = pluralize wordcount, "word"

          %span.author
            - author = data.authors[article.data.author]
            - if author
              by
              %span.name-full= author['name']

          %span.tags
            = article.tags.join ', '

      %td.viewlink
        = link_to "", article.url, {target: "_blank", title: "Open article in a new tab"}

      %td.date
        .date-format="#{article.date.to_date}"
        .date-ago="#{time_ago_in_words article.date}"


- content_for :tail do
  :coffee
    $newpostForm = $('#newpost')
    $newpostTitle = $('.title', $newpostForm)
    $form = $('#filterform')
    $filter = $('#filterbox')
    $clearer = $('#filterclear')
    delayTimer = null
    createAjax = null


    # Functions

    createPost = ->
      if $newpostTitle.val()
        createAjax = $.post $newpostForm.attr('action'), $newpostForm.serialize(), (data)->
          returnval = $.parseJSON data

          if returnval['slug'] != ''
            setTimeout ->
              window.location = "/admin/edit?date=" + returnval['date'] + "&slug=" + returnval['slug']
            , 500
          else
            do $newpostTitle.focus

      else
        console.log 'EMPTY!'
        do $newpostTitle.focus
        $('.helpertip', $newpostForm).fadeIn(300).slideDown(300)

    clearFilter = (e) ->
      setTimeout ->
        $filter.val('')
        do $filter.focus
        do updateList
        do updateClearer
      , 1

    updateClearer = ->
      $clearer.toggle($filter.val() != '')

    updateList = ->
      $.get '/admin/?filter=' + $filter.val(), (data) ->
        $('#articlelist').html $('#articlelist', data)

    activateFilter = (e) ->
      do updateClearer

      switch e.key
        when "Escape" then do clearFilter
        when "Esc" then do clearFilter
        when "Enter" then do e.preventDefault
        else
          clearTimeout delayTimer
          delayTimer = setTimeout ->
            do updateList
          , 500


    # Bindings

    $newpostTitle.on 'keypress', (e) ->
      $('.helpertip', $newpostForm).fadeOut(200)

    $newpostForm.on 'submit', (e) ->
      do createPost
      do e.preventDefault
      return false

    $form.on 'submit', (e) -> do e.preventDefault

    $filter.on 'keypress', activateFilter

    $clearer.on 'click', clearFilter

    # Workaround for cache w/ back/forward
    $(window).on 'load', updateList


    # On ready
    $ ->
      do LiveReload.shutDown

      do updateClearer
      do $filter.focus
<commit_msg>added title & page classes<commit_after>---
title: Administration
page_classes: admin admin-index
---
- content_for :head do
  = stylesheet_link_tag "lib/admin"

:ruby
  arg = request['params']
  filter = arg['filter']

  articles_filtered = if arg.empty?
      page_articles
    else
      current_list = page_articles
      tokens = filter.split(/ /)
      #tokens = filter.class == "string" ? [filter] : filter.map { |s| s.gsub /^['"]|['"]$/, '' }

      tokens.each do |token|
        current_list.select! {|a| a.body.downcase.match token.downcase}
      end

      current_list
    end


%form.form.form-horizontal.newpost#newpost{action: "/admin/newpost", method: "post"}
  .col-sm-7
    %input.title.form-control{name: "title", placeholder: "Post title", autocomplete: "off"}
    .helpertip
      Please enter a title for your new blog post.

  .col-sm-3
    %select.form-control{name: "author"}
      - data.authors.sort_by {|n, d| author_name n}.each do |nick, data|
        - if nick == ENV['USER']
          %option{value: nick, selected: true}= author_name nick
        - else
          %option{value: nick}= author_name nick

  .col-sm-s
    %button#create-post-action.btn.btn-primary.col-sm-2
      Create post

%hr

%form.form.form-horizontal.filterform#filterform{action: "/admin/", method: "post"}
  .filter-wrap.col-sm-12
    %input.form-control.col-sm-11#filterbox{name: "filter", value: filter, placeholder: "Search all posts", autocomplete: "off"}

    %button.btn.clearer#filterclear
      ×

    %noscript
      %button.btn.btn-primary.col-sm-1 Filter


%table.articles.blog-admin#articlelist
  - articles_filtered.each do |article|

    - post_date = article.date.strftime("%F")
    - post_slug = article.slug

    %tr.article{class: " #{article.published? ? 'published' : 'draft'}"}

      %td.published
        - unless article.published?
          %i.draft-icon{title: "Draft"}

      %td
        .title
          =link_to article.title, "/admin/edit?date=#{post_date}&slug=#{post_slug}", {style: "display: block", title: "Edit article"}

        .meta
          %span.wordcount
            - wordcount = Nokogiri::HTML(article.body).text.scan(/[\w]+/).size
            = pluralize wordcount, "word"

          %span.author
            - author = data.authors[article.data.author]
            - if author
              by
              %span.name-full= author['name']

          %span.tags
            = article.tags.join ', '

      %td.viewlink
        = link_to "", article.url, {target: "_blank", title: "Open article in a new tab"}

      %td.date
        .date-format="#{article.date.to_date}"
        .date-ago="#{time_ago_in_words article.date}"


- content_for :tail do
  :coffee
    $newpostForm = $('#newpost')
    $newpostTitle = $('.title', $newpostForm)
    $form = $('#filterform')
    $filter = $('#filterbox')
    $clearer = $('#filterclear')
    delayTimer = null
    createAjax = null


    # Functions

    createPost = ->
      if $newpostTitle.val()
        createAjax = $.post $newpostForm.attr('action'), $newpostForm.serialize(), (data)->
          returnval = $.parseJSON data

          if returnval['slug'] != ''
            setTimeout ->
              window.location = "/admin/edit?date=" + returnval['date'] + "&slug=" + returnval['slug']
            , 500
          else
            do $newpostTitle.focus

      else
        console.log 'EMPTY!'
        do $newpostTitle.focus
        $('.helpertip', $newpostForm).fadeIn(300).slideDown(300)

    clearFilter = (e) ->
      setTimeout ->
        $filter.val('')
        do $filter.focus
        do updateList
        do updateClearer
      , 1

    updateClearer = ->
      $clearer.toggle($filter.val() != '')

    updateList = ->
      $.get '/admin/?filter=' + $filter.val(), (data) ->
        $('#articlelist').html $('#articlelist', data)

    activateFilter = (e) ->
      do updateClearer

      switch e.key
        when "Escape" then do clearFilter
        when "Esc" then do clearFilter
        when "Enter" then do e.preventDefault
        else
          clearTimeout delayTimer
          delayTimer = setTimeout ->
            do updateList
          , 500


    # Bindings

    $newpostTitle.on 'keypress', (e) ->
      $('.helpertip', $newpostForm).fadeOut(200)

    $newpostForm.on 'submit', (e) ->
      do createPost
      do e.preventDefault
      return false

    $form.on 'submit', (e) -> do e.preventDefault

    $filter.on 'keypress', activateFilter

    $clearer.on 'click', clearFilter

    # Workaround for cache w/ back/forward
    $(window).on 'load', updateList


    # On ready
    $ ->
      do LiveReload.shutDown

      do updateClearer
      do $filter.focus

{'fraction_non_alphanumeric': 0.14772004241781547, 'fraction_numerical': 0.005090137857900318, 'mean_word_length': 2.2655817174515236, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 31, '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': '7363883', 'n_tokens_mistral': 3069, 'n_tokens_neox': 2943, 'n_words': 636}