Example #1
0
func GetCategorys(categorys []string) []Category {
	var categorysSet []Category

	for _, categoryStr := range categorys {
		categoryArry := strings.Split(strings.TrimSpace(categoryStr), "@")
		var category Category
		name := strings.Split(strings.TrimSpace(categoryArry[0]), "(")
		category.Name = strings.TrimSpace(name[0])
		if len(name) > 2 {
			log.Fatal(categoryStr + "配置格式有误(多个()符号),请检查确认!")
		} else if len(name) > 1 {
			category.Alias = url.QueryEscape(pinyin.Convert(strings.TrimSpace(strings.TrimSuffix(strings.TrimSpace(name[1]), ")")), ""))
		} else {
			category.Alias = url.QueryEscape(pinyin.Convert(category.Name, ""))
		}
		if len(categoryArry) > 2 {
			log.Fatal(categoryStr + "配置格式有误(多个@符号),请检查确认")
		} else if len(categoryArry) > 1 {
			category.Href = strings.TrimSpace(categoryArry[1])
		}
		if len(category.Href) > 0 {
			category.Count = -1
		} else {
			category.Count = 0
		}

		categorysSet = append(categorysSet, category)
	}

	return categorysSet
}
Example #2
0
//解析日志信息
func Decode_log(src string, siteInfo SiteInfo) LogInfo { //decode_log

	logType := Parse_logType(src)

	var logInfo LogInfo

	if logType == "article" { //文章

		logInfo = decode_article(src)

	} else if logType == "album" { //相册

		logInfo = decode_album(src)

	} else {

		log.Fatal("解析日志:未知类型的日志目录,目录结构不符合预期!")

	}
	//读取标题、日期等信息
	fileName := filepath.Base(src)
	pos := strings.LastIndex(fileName, "@")
	if pos >= 0 {
		logInfo.Title = fileName[0:pos]
		_date := strings.TrimSuffix(fileName[pos+1:len(fileName)], ".md")
		// t, err := time.Parse("2006-5-5", logInfo.Date)
		loc, _ := time.LoadLocation("Local")
		t, err := time.ParseInLocation("2006-1-2", _date, loc)
		if err != nil {
			log.Println(err)
			log.Fatal("日志日期填写格式错误,请参照2006-1-2这样的格式,无前导!")
		}
		logInfo.Date = TimeStamp(t.Unix())
	} else {
		log.Fatal(fileName + "日志文件名不合法,请修改后再build")
	}

	if logInfo.MetaData["alias"] == "" {
		logInfo.Permalink = url.QueryEscape(pinyin.Convert(logInfo.Title, "-"))
	} else {
		logInfo.Permalink = logInfo.MetaData["alias"]
	}

	for _, category := range siteInfo.Categorys {
		if strings.Contains(logInfo.MetaData["category"], category.Name) {
			logInfo.Categorys = append(logInfo.Categorys, category)
		}
	}
	for _, tag := range siteInfo.Tags {
		if strings.Contains(logInfo.MetaData["tag"], tag.Name) {
			logInfo.Tags = append(logInfo.Tags, tag)
		}
	}
	return logInfo
}
Example #3
0
func GetTags(tags []string) []Tag {
	var tagSet []Tag

	for _, tagStr := range tags {
		var tag Tag
		name := strings.Split(strings.TrimSpace(tagStr), "(")
		tag.Name = strings.TrimSpace(name[0])

		if len(name) > 2 {
			log.Fatal(tagStr + "配置格式有误(多个()符号),请检查确认!")
		} else if len(name) > 1 {
			tag.Alias = url.QueryEscape(pinyin.Convert(strings.TrimSpace(strings.TrimSuffix(strings.TrimSpace(name[1]), ")")), ""))
		} else {
			tag.Alias = url.QueryEscape(pinyin.Convert(tag.Name, ""))
		}
		tagSet = append(tagSet, tag)
	}

	return tagSet
}