<commit_before>package controllers

import (
	"html/template"
	"net/http"
	"strings"

	"github.com/chenxin0723/ilove/config/admin"
	"github.com/chenxin0723/ilove/config/bindatafs"
	"github.com/chenxin0723/ilove/utils"
	"github.com/gin-gonic/gin"
	"github.com/qor/render"
)

var Render *render.Render

func init() {
	Render = render.New(&render.Config{ViewPaths: []string{"app/views"}})
	Render.SetAssetFS(bindatafs.AssetFS.NameSpace("views"))
}

func SetContext(ctx *gin.Context) {
	funcMap := utils.FuncMap(ctx.Writer, ctx.Request)
	ctx.Set("FuncMap", funcMap)
}

func Home(ctx *gin.Context) {
	FuncMap := ctx.MustGet("FuncMap").(template.FuncMap)
	viewCtx := map[string]interface{}{}
	if isDraft(ctx.Request) {
		qorAdminCssJs := template.HTML(`<script type="text/javascript" src="/system/qor_vendor.js"></script><link rel="stylesheet" href="/system/qor_admin.css"><script defer async type="text/javascript" src="/system/qor_admin.js"></script>`)
		viewCtx["ActionBar"] = qorAdminCssJs + admin.ActionBar.Render(ctx.Writer, ctx.Request)
	}

	viewCtx["PageType"] = "Homepage"
	Render.Layout("application").Funcs(FuncMap).Execute("index", viewCtx, ctx.Request, ctx.Writer)
	return
}

func isDraft(r *http.Request) bool {
	return !strings.Contains(r.Host, "draft-")
}
<commit_msg>add action bar to draft site<commit_after>package controllers

import (
	"html/template"
	"net/http"
	"strings"

	"github.com/chenxin0723/ilove/config/admin"
	"github.com/chenxin0723/ilove/config/bindatafs"
	"github.com/chenxin0723/ilove/utils"
	"github.com/gin-gonic/gin"
	"github.com/qor/render"
)

var Render *render.Render

func init() {
	Render = render.New(&render.Config{ViewPaths: []string{"app/views"}})
	Render.SetAssetFS(bindatafs.AssetFS.NameSpace("views"))
}

func SetContext(ctx *gin.Context) {
	funcMap := utils.FuncMap(ctx.Writer, ctx.Request)
	ctx.Set("FuncMap", funcMap)
}

func Home(ctx *gin.Context) {
	FuncMap := ctx.MustGet("FuncMap").(template.FuncMap)
	viewCtx := map[string]interface{}{}
	if isDraft(ctx.Request) {
		qorAdminCssJs := template.HTML(`<script type="text/javascript" src="/system/qor_vendor.js"></script><link rel="stylesheet" href="/system/qor_admin.css"><script defer async type="text/javascript" src="/system/qor_admin.js"></script>`)
		viewCtx["ActionBar"] = qorAdminCssJs + admin.ActionBar.Render(ctx.Writer, ctx.Request)
	}

	viewCtx["PageType"] = "Homepage"
	Render.Layout("application").Funcs(FuncMap).Execute("index", viewCtx, ctx.Request, ctx.Writer)
	return
}

func isDraft(r *http.Request) bool {
	return strings.Contains(r.Host, "draft")
}

{'fraction_non_alphanumeric': 0.17516543402101986, 'fraction_numerical': 0.009342156481121059, 'mean_word_length': 5.890080428954423, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '7199780', 'n_tokens_mistral': 964, 'n_tokens_neox': 951, 'n_words': 135}