<commit_before>class SitePostsController < ApplicationController
  before_action :setup_site
  layout 'site_posts'

  def index
    @posts = @site.posts
  end

  def show
    @post = @site.posts.find(params[:id])
  end

  private
  def setup_site
    @site = Site.find(site_id)
  end

  def site_id
    # NOTE: env['SERVER_NAME'] よりも、 request.domain や
    #       request.subdomain のほうがいいかもしれない。
    # 例: http://site1.lvh.me/ の場合
    #   * env['SERVER_NAME']  #=> site1.lvh.me
    #   * request.domain      #=> lvh.me
    #   * request.subdomain   #=> site1
    case env['SERVER_NAME']
    when /\Asite1\./
      1
    when /\Asite2\./
      2
    else
      params[:site_id]
    end<commit_msg>Setup site properly<commit_after>class SitePostsController < ApplicationController
  before_action :setup_site
  layout 'site_posts'

  def index
    @posts = @site.posts
  end

  def show
    @post = @site.posts.find(params[:id])
  end

  private

  def setup_site
    if params[:site_id]
      # for test and debug
      @site = Site.find(params[:site_id])
    else
      @site = Site.where(fqdn: request.server_name).first
    end
{'fraction_non_alphanumeric': 0.1125886524822695, 'fraction_numerical': 0.0062056737588652485, 'mean_word_length': 2.5615141955835963, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, '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': '2479714', 'n_tokens_mistral': 415, 'n_tokens_neox': 400, 'n_words': 86}