<commit_before>require 'digest'
require 'pathname'

# encoding: utf-8
#
# Jekyll publisher for privateley public posts.
#
# Version: 0.3.0
#
# Author: <NAME>
# Site: http://www.alwayscoding.ca
# Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
#
# A generator that creates privately public pages. Pages secured only by url
# obscurity. Links are published to the console during generation or via rake
# task. Links can be given to friends for previewing.

module Jekyll

  class Site
    attr_accessor :privpub_posts

    alias_method :previous_reset, :reset
    def reset
      self.privpub_posts = []
      previous_reset
    end

    alias_method :previous_render, :render
    def render
      payload = site_payload
      self.privpub_posts.each do |post|
        post.render(self.layouts, payload)
      end
      previous_render
    rescue Errno::ENOENT => e
      # ignore missing layout dir
    end

    alias_method :previous_write, :write
    def write
      self.privpub_posts.each do |post|
        post.write(self.dest)
      end
      previous_write
    end
  end

  module PrivatelyPublic

    class Post < Jekyll::Post
      def permalink
        "#{privpub_path}/#{digest}/#{CGI.escape(slug)}"
      end

      protected

      def privpub_path
        !site.config[:privpub_path].nil? ? Pathname.new("/#{site.config[:privpub_path]}").cleanpath : '/private'
      end

      def digest
        CGI.escape(Digest::SHA1.hexdigest(slug)[0...6])
      end
    end

    class Generator < Jekyll::Generator
      safe true
      priority :normal

      def read_posts(site, dir = '')
        entries = site.get_entries(dir, '_posts')

        # first pass processes, but does not yet render post content
        entries.each do |f|
          if Post.valid?(f)
            post = Post.new(site, site.source, '', f)

            if post.data.has_key?('privpub') && post.data['privpub'] == true
              site.privpub_posts << post
            end
          end
        end<commit_msg>Break the private methods out into a module so they can be used on pages as well.<commit_after>require 'digest'
require 'pathname'

# encoding: utf-8
#
# Jekyll publisher for privateley public posts.
#
# Version: 0.3.0
#
# Author: <NAME>
# Site: http://www.alwayscoding.ca
# Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
#
# A generator that creates privately public pages. Pages secured only by url
# obscurity. Links are published to the console during generation or via rake
# task. Links can be given to friends for previewing.

module Jekyll

  class Site
    attr_accessor :privpub_posts

    alias_method :previous_reset, :reset
    def reset
      self.privpub_posts = []
      previous_reset
    end

    alias_method :previous_render, :render
    def render
      payload = site_payload
      self.privpub_posts.each do |post|
        post.render(self.layouts, payload)
      end
      previous_render
    rescue Errno::ENOENT => e
      # ignore missing layout dir
    end

    alias_method :previous_write, :write
    def write
      self.privpub_posts.each do |post|
        post.write(self.dest)
      end
      previous_write
    end
  end

      end

  module PrivatelyPublic
    module Permalinks
      protected

      def privpub_path
        !site.config[:privpub_path].nil? ? Pathname.new("/#{site.config[:privpub_path]}").cleanpath : '/private'
      end

      def digest
        CGI.escape(Digest::SHA1.hexdigest(slug)[0...6])
      end
    end

    class Post < Jekyll::Post
      include PrivatelyPublic::Permalinks

      def permalink
        "#{privpub_path}/#{digest}/#{CGI.escape(slug)}"
      end
    end

    class Generator < Jekyll::Generator
      safe true
      priority :normal

      def read_posts(site, dir = '')
        entries = site.get_entries(dir, '_posts')

        # first pass processes, but does not yet render post content
        entries.each do |f|
          if Post.valid?(f)
            post = Post.new(site, site.source, '', f)

            if post.data.has_key?('privpub') && post.data['privpub'] == true
              site.privpub_posts << post
            end
          end
        end
{'fraction_non_alphanumeric': 0.09561091340450771, 'fraction_numerical': 0.0033214709371293, 'mean_word_length': 2.4416326530612245, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '787900', 'n_tokens_mistral': 1284, 'n_tokens_neox': 1254, 'n_words': 357}