Example #1
0
func createLinks(elements []input.ContentData, fromIndex bool) string {
	sortedElements := elements[:]

	sort.Sort(sort.Reverse(sortableByDate(sortedElements)))
	content := ""

	for _, element := range sortedElements {
		slug := slug.GenerateSlug(element.Title)
		dateString :=
			fmt.Sprintf(
				"(%d-%02d-%02d) ",
				element.Date.Year(),
				element.Date.Month(),
				element.Date.Day())
		rawLink := "content/" + slug + ".html"

		if !fromIndex {
			rawLink = "../" + rawLink
		}

		content += generateLink(rawLink, dateString+element.Title) + "</br>\n"
	}

	return content
}
Example #2
0
func TestCreateIndexPageOrdered(t *testing.T) {
	data := CreateIndex(testConfigData, []input.ContentData{testContentData3, testContentData1, testContentData2})

	index1 := strings.Index(data, slug.GenerateSlug(testContentData1.Title))
	index2 := strings.Index(data, slug.GenerateSlug(testContentData2.Title))
	index3 := strings.Index(data, slug.GenerateSlug(testContentData3.Title))

	correctOrder := (index1 < index2) && (index2 < index3)
	validIndices := (index1 > 0) && (index2 > 0) && (index3 > 0)

	if !validIndices {
		t.Error("invalid  indices (the titles are not present) !")
	}

	if !correctOrder {
		t.Error("incorrect order !")
	}
}
Example #3
0
func TestCreateContent(t *testing.T) {
	outputDirectory, configData, elements := setupTestEnvironment("3")
	contentPath := filepath.Join(outputDirectory, "content")
	test.CreateTestDirectory(contentPath)
	content := elements[0]

	CreateContentPage(outputDirectory, configData, content, elements, test.BaseHtmlContent)
	expected := "Old Pages ||| <p>foo</p>\n ||| <p>2015-03-24 22:28</p></br>\n<h2>Old Pages</h2>\n<p>Old unsupported pages :</p>\n ||| <a href=\"../index.html\">Index</a></br>\n</br>\n<a href=\"../categories/x1.html\">X1</a></br>\n<a href=\"../categories/x2.html\">X2</a> ||| <p>© foo</p>\n"

	filePath := filepath.Join(contentPath, slug.GenerateSlug(test.ContentDataTitle)+".html")
	result := test.GetTestFileContent(filePath)

	test.TestValues(t, expected, result, "incorrect page generated")
}
Example #4
0
func TestCreateCategory(t *testing.T) {
	outputDirectory, configData, elements := setupTestEnvironment("2")
	category := test.ContentDataCategories[0]
	categoryPath := filepath.Join(outputDirectory, "categories")
	test.CreateTestDirectory(categoryPath)

	CreateCategoryPage(outputDirectory, configData, category, elements, test.BaseHtmlContent)
	expected := "X1 ||| <p>foo</p>\n ||| <h2>X1</h2>\n<a href=\"../content/old-pages.html\">(2015-03-24) Old Pages</a></br>\n ||| <a href=\"../index.html\">Index</a></br>\n</br>\n<a href=\"../categories/x1.html\">X1</a></br>\n<a href=\"../categories/x2.html\">X2</a> ||| <p>© foo</p>\n"

	filePath := filepath.Join(categoryPath, slug.GenerateSlug(category)+".html")
	result := test.GetTestFileContent(filePath)

	test.TestValues(t, expected, result, "incorrect page generated")
}
Example #5
0
func GenerateSidebar(configData input.ConfigData, elements []input.ContentData, forIndexPage bool) string {
	categories := CollectCategories(elements)
	linkPrefix := "../"

	if forIndexPage {
		linkPrefix = ""
	}

	result := generateLink(linkPrefix+"index.html", configData.IndexName) + "</br>\n"

	for _, category := range categories {
		slug := slug.GenerateSlug(category)
		rawLink := linkPrefix + "categories/" + slug + ".html"
		result += "</br>\n" + generateLink(rawLink, category)
	}

	return result
}
Example #6
0
func CreateCategoryPage(outputDirectory string, configData input.ConfigData, categoryToDisplay string, elements []input.ContentData, baseHtml string) {
	stringContent := category.CreateCategoryPage(configData, categoryToDisplay, elements)
	outputFile := outputDirectory + "/categories/" + slug.GenerateSlug(categoryToDisplay) + ".html"

	createPage(categoryToDisplay, outputFile, configData, elements, false, stringContent, baseHtml)
}
Example #7
0
func CreateContentPage(outputDirectory string, configData input.ConfigData, content input.ContentData, elements []input.ContentData, baseHtml string) {
	stringContent := markdown.CreateContent(configData, content)
	outputFile := outputDirectory + "/content/" + slug.GenerateSlug(content.Title) + ".html"

	createPage(content.Title, outputFile, configData, elements, false, stringContent, baseHtml)
}