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

WIP: Fix wikilinks slug querying #386

Merged
merged 2 commits into from
Nov 28, 2020
Merged
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 packages/foam-core/src/markdown-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const wikilinkPlugin: ParserPlugin = {
if (node.type === 'wikiLink') {
note.links.push({
type: 'wikilink',
slug: nameToSlug(node.value as string),
slug: node.value as string,
position: node.position!,
});
}
Expand Down
4 changes: 2 additions & 2 deletions packages/foam-core/src/note-graph.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Graph } from 'graphlib';
import { URI, ID, Note, NoteLink } from './types';
import { computeRelativeURI } from './utils';
import { computeRelativeURI, nameToSlug } from './utils';
import { Event, Emitter } from './common/event';

export type GraphNote = Note & {
Expand Down Expand Up @@ -91,7 +91,7 @@ export class NoteGraph implements NoteGraphAPI {
// prettier-ignore
const filterFn =
query == null ? (note: Note | null) => note != null
: 'slug' in query ? (note: Note | null) => note?.slug === query.slug
: 'slug' in query ? (note: Note | null) => [nameToSlug(query.slug), query.slug].includes(note?.slug as string)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am checking for both [[Slug Name]] and [[slug-name]] here, however they are defined in the note, so both can be used interchangably.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SanketDG I have a feeling this wouldn't work with the dataviz graph, have you tested it?

Copy link
Contributor Author

@SanketDG SanketDG Nov 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it definitely works with my notes, which all have filenames like "javascript-execution.md" and referenced as [[Javascript Execution]], this is uniform throughout.

Any other cases you want me to check?

: 'title' in query ? (note: Note | null) => note?.title === query.title
: (note: Note | null) => note != null;

Expand Down
4 changes: 2 additions & 2 deletions packages/foam-core/test/markdown-provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ describe('Markdown loader', () => {
const noteA = graph.setNote(createNoteFromMarkdown('/page-a.md', pageA));
const noteB = graph.setNote(createNoteFromMarkdown('/page-b.md', pageB));
graph.setNote(createNoteFromMarkdown('/page-c.md', pageC));
graph.setNote(createNoteFromMarkdown('/page-d.md', pageD));
graph.setNote(createNoteFromMarkdown('/page-e.md', pageE));
graph.setNote(createNoteFromMarkdown('/Page D.md', pageD));
graph.setNote(createNoteFromMarkdown('/page e.md', pageE));

expect(
graph.getBacklinks(noteB.id).map(link => graph.getNote(link.from)!.slug)
Expand Down