Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove filter by slug key #274

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ app.use(pages)
app.use(cache)

// category pages will be cache busted when their last updated timestamp changes
app.use(categories)
app.use(categories.router)
app.use(playlists)

postload.forEach((middleware) => app.use(middleware))
Expand Down
11 changes: 4 additions & 7 deletions server/routes/categories.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const {getTemplates, sortDocs, stringTemplate} = require('../utils')
const {parseUrl} = require('../urlParser')

router.get('*', handleCategory)
module.exports = router
module.exports = {router, createRelatedList}

const categories = getTemplates('categories')

Expand Down Expand Up @@ -94,12 +94,10 @@ function prepareContextualData(data, url, breadcrumb, parent, slug) {

const {children: siblings} = parent
const {children} = data
const self = url.split('/').slice(-1)[0]
// most of what we are doing here is preparing parents and siblings
// we need the url and parent object, as well as the breadcrumb to do that
const siblingLinks = createRelatedList(siblings, self, `${url.split('/').slice(0, -1).join('/')}`)
const childrenLinks = createRelatedList(children || {}, self, url)

const siblingLinks = createRelatedList(siblings)
const childrenLinks = createRelatedList(children || {})
// extend the breadcrumb with render data
const parentLinks = url
.split('/')
Expand All @@ -121,9 +119,8 @@ function prepareContextualData(data, url, breadcrumb, parent, slug) {
}
}

function createRelatedList(slugs, self, baseUrl) {
function createRelatedList(slugs) {
return Object.keys(slugs)
.filter((slug) => slug !== self)
.map((slug) => {
const {id} = slugs[slug]
const {sort, prettyName, webViewLink, path: url, resourceType, tags} = getMeta(id)
Expand Down
59 changes: 59 additions & 0 deletions test/unit/categories.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
'use strict'
const sinon = require('sinon')
const list = require('../../server/list')
const {assert} = require('chai')

describe('categories', () => {
const sampleChildren = {
'test-duplicate-title-bug': {
nodeType: 'leaf',
prettyName: 'Test Duplicate Title Bug',
home: undefined,
homePrettyName: undefined,
id: '1Mk6PB_kprmtPaQ3UULjTQ4msv24qfo6yOqMBBxYIzuo',
breadcrumb: [[{}]],
sort: 'Test Duplicate Title Bug | team'
}
}

afterEach(() => {
sinon.restore()
})

it('should not remove items matching the parent', () => {
const expected = [
{
sort: 'Test Duplicate Title Bug | team',
name: 'Test Duplicate Title Bug',
editLink: 'https://docs.google.com/document/d/1Mk6PB_kprmtPaQ3UULjTQ4msv24qfo6yOqMBBxYIzuo/edit?usp=drivesdk',
resourceType: 'document',
url: '/test-duplicate-title-bug/test-duplicate-title-bug',
tags: ['team']
}
]
sinon.stub(list, 'getMeta').returns({
id: '1Mk6PB_kprmtPaQ3UULjTQ4msv24qfo6yOqMBBxYIzuo',
name: 'Test Duplicate Title Bug | team',
parents: ['1DlHbZAobaiv6IkUP0O6FM6lAvufJZlPT'],
webViewLink: 'https://docs.google.com/document/d/1Mk6PB_kprmtPaQ3UULjTQ4msv24qfo6yOqMBBxYIzuo/edit?usp=drivesdk',
prettyName: 'Test Duplicate Title Bug',
tags: ['team'],
resourceType: 'document',
sort: 'Test Duplicate Title Bug | team',
slug: 'test-duplicate-title-bug',
folder: {
id: '1DlHbZAobaiv6IkUP0O6FM6lAvufJZlPT',
webViewLink: 'https://drive.google.com/drive/folders/1DlHbZAobaiv6IkUP0O6FM6lAvufJZlPT',
prettyName: 'Test Duplicate Title Bug',
tags: ['team'],
resourceType: 'folder',
sort: 'Test Duplicate Title Bug | team',
path: '/test-duplicate-title-bug'
},
topLevelFolder: {path: '/', tags: []},
path: '/test-duplicate-title-bug/test-duplicate-title-bug'
})
const {createRelatedList} = require('../../server/routes/categories') // we have to import here to populate the local cache
assert.deepEqual(createRelatedList(sampleChildren), expected)
})
})