Example #1
0
func (p *Page) HasMenuCurrent(menu string, me *MenuEntry) bool {
	menus := p.Menus()
	sectionPagesMenu := helpers.Config().GetString("SectionPagesMenu")

	// page is labeled as "shadow-member" of the menu with the same identifier as the section
	if sectionPagesMenu != "" && p.Section() != "" && sectionPagesMenu == menu && p.Section() == me.Identifier {
		return true
	}

	if m, ok := menus[menu]; ok {
		if me.HasChildren() {
			for _, child := range me.Children {
				if child.IsEqual(m) {
					return true
				}
				if p.HasMenuCurrent(menu, child) {
					return true
				}
			}
		}
	}

	return false

}
Example #2
0
func TestLoadGlobalConfig(t *testing.T) {
	// Add a random config variable for testing.
	// side = page in Norwegian.
	configContent := `
	PaginatePath = "side"
	`

	writeSource(t, "hugo.toml", configContent)

	require.NoError(t, LoadGlobalConfig("", "hugo.toml"))
	assert.Equal(t, "side", helpers.Config().GetString("paginatePath"))
	// default
	assert.Equal(t, "layouts", viper.GetString("LayoutDir"))
}
Example #3
0
func newPaginationURLFactory(pathElements ...string) paginationURLFactory {
	paginatePath := helpers.Config().GetString("paginatePath")

	return func(page int) string {
		var rel string
		if page == 1 {
			rel = fmt.Sprintf("/%s/", path.Join(pathElements...))
		} else {
			rel = fmt.Sprintf("/%s/%s/%d/", path.Join(pathElements...), paginatePath, page)
		}

		return helpers.URLizeAndPrep(rel)
	}
}
Example #4
0
func resolvePagerSize(options ...interface{}) (int, error) {
	if len(options) == 0 {
		return helpers.Config().GetInt("paginate"), nil
	}

	if len(options) > 1 {
		return -1, errors.New("too many arguments, 'pager size' is currently the only option")
	}

	pas, err := cast.ToIntE(options[0])

	if err != nil || pas <= 0 {
		return -1, errors.New(("'pager size' must be a positive integer"))
	}

	return pas, nil
}