Skip to content

Commit

Permalink
Merge pull request #388 from mgdesign/master
Browse files Browse the repository at this point in the history
ShowOnMenu can now be used to show and hide pages on the site menu
  • Loading branch information
ryanlelek authored Feb 21, 2024
2 parents 65e3112 + 951d098 commit 6eebb5d
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 5 deletions.
7 changes: 7 additions & 0 deletions app/core/contents.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ async function handler(activePageSlug, config) {
slug: '.',
title: '',
show_on_home: true,
show_on_menu: true,
is_index: true,
active: baseSlug === '',
class: 'category-index',
Expand Down Expand Up @@ -115,6 +116,9 @@ async function processFile(config, activePageSlug, contentDir, filePath) {
: config.show_on_home_default,
is_index: false,
is_directory: true,
show_on_menu: dirMetadata.show_on_menu
? dirMetadata.show_on_menu === 'true'
: config.show_on_menu_default,
active: activePageSlug.startsWith(`/${fileSlug}`),
class: `category-${contentProcessors.cleanString(fileSlug)}`,
sort: dirMetadata.sort || sort,
Expand Down Expand Up @@ -148,6 +152,9 @@ async function processFile(config, activePageSlug, contentDir, filePath) {
? meta.show_on_home === 'true'
: config.show_on_home_default,
is_directory: false,
show_on_menu: meta.show_on_menu
? meta.show_on_menu === 'true'
: config.show_on_menu_default,
active: activePageSlug.trim() === `/${slug}`,
sort: pageSort,
};
Expand Down
12 changes: 11 additions & 1 deletion app/routes/wildcard.route.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Modules
var path = require('path');
var _ = require('underscore');
var fs = require('fs-extra');
const { marked } = require('marked');
var toc = require('markdown-toc');
Expand Down Expand Up @@ -100,7 +101,16 @@ function route_wildcard(config) {

var pageList = remove_image_content_directory(
config,
await contentsHandler(slug, config)
_.chain(await contentsHandler(slug, config))
.filter((page) => page.show_on_menu)
.map((page) => {
page.files = _.filter(page.files, (file) => {
return file.show_on_menu
});
return page;
})
.value()

);

var loggedIn =
Expand Down
4 changes: 4 additions & 0 deletions config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ var config = {
// all categories or files that do not specify ShowOnHome meta property will be shown
show_on_home_default: true,

// Controls behavior of the menu if meta ShowOnMenu is not present. If set to true
// all categories or files that do not specify ShowOnMenu meta property will be shown
show_on_menu_default: true,

// Theme (see top of file)
theme_dir,
theme_name,
Expand Down
5 changes: 3 additions & 2 deletions content/pages/usage/category-meta.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ You can add a file called meta (with no extension) in the category folder. This

* Title - This variable will override the title based on the folder name.
* Sort - This variable will affect the sorting of the categories.
* ShowOnHome - Optional. If false, categoru won't show on the home page. Default behavior can be changed through `config.show_on_home_default`.
* ShowOnHome - Optional. If false, category won't show on the home page. Default behavior can be changed through `config.show_on_home_default`.
* ShowOnMenu - Optional. If false, category won't show on the site menu. Default behavior can be changed through `config.show_on_menu_default`.
* Description - Optional. This variable will provide a variable to be used in the templates, for example in the hompage, to enhance and clarify the content of the category.

Note that `config.show_on_home_default` sets the default behavior for pages too.
Note that `config.show_on_home_default` and `config.show_on_menu_default` will sets the default behavior for pages too.
5 changes: 3 additions & 2 deletions content/pages/usage/page-meta.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
Title: Page Meta
Description: This page describes how the Meta information works.
Modified: 2016-09-14T11:50:00-0500
Modified: 2023-09-15T19:00:00-0100
---

Each page can contain optional meta data about the page. This is useful when you need the page to have a different
Expand All @@ -12,8 +12,9 @@ should be written in [YAML](https://yaml.org/spec/1.2.2/).
* Description - This variable will give `lunr` a description to search on.
* Sort - This variable will affect the sorting of the pages inside the category.
* ShowOnHome - Optional. If false, page won't be listed on the home page. Default behavior can be changed through `config.show_on_home_default`.
* ShowOnMenu - Optional. If false, page won't be listed on the site menu. Default behavior can be changed through `config.show_on_menu_default`.
* Modified - This variable will override the modified date based on the file name.
* This should be in full ISO 8601 format including Time and Timezone offset.

Before version 0.11.0 these meta blocks could only be HTML comments (/\* \*/).
Before version 0.11.0 these meta blocks could only be HTML comments (/\* \*/).
Starting with version 0.11.0, the meta blocks should be YAML blocks.
1 change: 1 addition & 0 deletions content/pages/what-is-raneto.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Title: What is Raneto?
Sort: 1
ShowOnHome: true
ShowOnMenu: false
---

Raneto is a Knowledgebase platform for [Node.js](https://nodejs.org/) that uses static
Expand Down
1 change: 1 addition & 0 deletions test/content/hidden-page.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Title: Hidden Page
Sort: 4
ShowOnHome: false
ShowOnMenu: false
*/

This page shoulnd't appear on the home page.
1 change: 1 addition & 0 deletions test/content/sub/not_on_home/meta
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Title: Not on home page
Sort: 2
ShowOnHome: false
ShowOnMenu: false
52 changes: 52 additions & 0 deletions test/raneto-core.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const config = {
page_sort_meta: 'sort',
category_sort: true,
show_on_home_default: true,
show_on_menu_default: true,
searchExtraLanguages: ['ru'],
debug: false,
content_dir: path.join(__dirname, 'content/'),
Expand Down Expand Up @@ -284,8 +285,59 @@ describe('#getPages()', () => {
);
expect(result[0]).to.have.property('show_on_home', true);
});

it('adds show_on_menu property to directory', async () => {
const result = await contentsHandler(null, config);
expect(result[0]).to.have.property('show_on_menu', true);
});

it('adds show_on_menu property to files', async () => {
const result = await contentsHandler(null, config);
expect(result[0].files[0]).to.have.property('show_on_menu', true);
});

it('loads meta show_on_menu value from directory', async () => {
const result = await contentsHandler(null, config);
expect(result[3]).to.have.property('show_on_menu', false);
});

it('loads meta show_on_menu value from file', async () => {
const result = await contentsHandler(null, config);
expect(result[0].files[4]).to.have.property('show_on_menu', false);
});

it('applies show_on_menu_default in absence of meta for directories', async () => {
const result = await contentsHandler(
null,
Object.assign(config, {
show_on_menu_default: false,
})
);
expect(result[1]).to.have.property('show_on_menu', false);
});

it('applies show_on_menu_default in absence of meta for files', async () => {
const result = await contentsHandler(
null,
Object.assign(config, {
show_on_menu_default: false,
})
);
expect(result[1].files[0]).to.have.property('show_on_menu', false);
});

it('category main always shows on menu', async () => {
const result = await contentsHandler(
null,
Object.assign(config, {
show_on_menu_default: false,
})
);
expect(result[0]).to.have.property('show_on_menu', true);
});
});


describe('#doSearch()', () => {
it('returns an array of search results', async () => {
const result = await searchHandler('example', config);
Expand Down

0 comments on commit 6eebb5d

Please sign in to comment.