GithubHelp home page GithubHelp logo

gatsby-theme-brain's Introduction

Gatsby Brain

Use this theme to integrate Roam Research inspired bidirectional linking of notes into a network on your site.

View a demo at https://twitter.com/aengusmcmillin/status/1249845320239984640

Note: This Theme Requires NodeJS v12

If you encounter an error along the lines of content.matchAll(...) is not a function, you will need to update your version of node to version 12.

Features

Double square bracket linking

This is the core feature of the plugin. Based on the model developed by Roam Research, the way it works is that any piece of text wrapped in double square brackets (for example [[some idea]]) will turn into a link to a page. If the page already exists in the graph it will link to that, and if not it will create the page. And when generating that page, a reference is created back to any files that link to it.

This means that you can create pages without any files backing them. They won't have any content, but they will still have the associated backlinks, which makes it incredibly easy to start linking together different notes and references based on common ideas.

For example, lets say you were writing a couple of book reviews on your site. You might create a note for each book as individual markdown files. Now, you could also create a 'books.md' file and add in links to all of your book reviews, but that would be a hassle. Instead, you can simply add something Tags: [[Books]] to the top of the each book as you create those notes, and a Books page will be automatically generated containing links to every one of your book reviews!

Case insensitivity

This is one variation from Roam. In Roam, everything is case sensitive, so if you use [[Book]] and [[book]], those will link to two different places. Because of the way this theme works it didn't make sense to keep that behavior, and I personally get frustrated with it more often than not. So this theme is case insensitive. That means linking to [[Book]], [[BOOK]], and [[book]] all go to the same place.

Add Frontmatter for titles and aliases

When generating a page from markdown, by default the title of the page will simply be the slug (filename minus extension) of the file. This is often not going to be exactly what you want due to the present of dashes and differences in capitalization. To fix this, you can add frontmatter to your markdown files with the title field filled in.

For example:

---
title: "Some Great Idea I Had"
---

And there is also a feature that isn't in Roam but can help a little bit with making a Public Brain more readable. It is another attribute of frontmatter called aliases. If you pass an array of strings to aliases, during the generation of the graph any double bracketed phrases that match one of those aliases will be linked to that note.

This can be useful for shorthands, plurals, or common misspellings. My favorite way is definitely for plurals so far though. Between this and the case insensitivity, it means you can easily set it up so that, for example, despite having a 'Books' page, you can easily write something like: "Lord of the Rings is a really good [[book]]", and not force yourself to rewrite it as "Lord of the Rings is a really good [[Books]]" for the sake of linking.

You would just make sure that your books markdown file has something like this at the top:

---
title: "Books"
aliases: ["book"]
---

Installation

To use this theme in your Gatsby site:

  1. Install the theme
npm install --save @aengusm/gatsby-theme-brain
  1. Add the theme to your gatsby-config.js:
module.exports = {
  plugins: ['@aengusm/gatsby-theme-brain'],
};
  1. Add content to Your Brain by creating a content/brain/ folder in the root of your site and adding markdown files to it. Use [[This Format]] to generate pages and links between pages.

  2. Start your site:

gatsby develop

Styling

For now the way to style this theme is with component shadowing. There is a single component that renders the layout for each brain note in src/components/BrainNote.js. If you wish to shadow this and create your own version, create the file src/@aengusm/gatsby-theme-brain/components/BrainNote.js. That will shadow the existing component and you can do whatever you want with it.

If you want an example of how I shadow this, checkout my websites github

Extending the GraphOverview component

If you want to modify the Graph Overview page you can do so by extending the GraphOverview component.

Here's an example of extending the component to fill the parent and be responsive to the current theme:

// src/@aengusm/gatsby-theme-brain/components/GraphOverview.js

import GraphOverview from "@aengusm/gatsby-theme-brain/src/components/GraphOverview";
import React from "react";
import { useColorMode } from "@chakra-ui/core";

import SEO from "../../../components/SEO";
import Layout from "../../../components/Layout";

export default (props) => {
  const { colorMode } = useColorMode();

  return (
    <Layout>
      <SEO title="Graph Overview" />
      <GraphOverview
        style={{ width: "100%", height: "100%" }}
        stylesheet={[
          {
            selector: "node",
            style: {
              label: "data(label)",
              color: colorMode === "light" ? "#000000" : "#ffffff",
              backgroundColor: "#545454",
              "text-wrap": "wrap",
              "text-max-width": 100,
              "font-size": 12,
            },
          },
        ]}
        {...props}
      />
    </Layout>
  );
};

Usage

Option Default Value Description
notesDirectory "content/brain/" Directory containing your brain note files
notesFileExtensions [".md", ".mdx"] File extensions that will be used to generate pages.
exclude [] List of strings or regular expressions. Notes files whose names match these will be ignored.
noteTemplate "./templates/brain.js" Template to use for note rendering
additionalNoteTypes {} Additional note types. This should be a mapping from a type string to a template path. (for example, {"evergreen": "./templates/evergreen.js"} would allow you to declare noteType: "evergreen" in your frontmatter to use that other template)
rootPath "brain" Set the root url for the brain on your site (e.g. in this case https://example.com/brain)
rootNote "brain" Name of the 'index' note. So in this case brain.md would generate the root page of the brain
generateSlug (filename) => slugify(filename) Function used to turn the filename of a note into its resulting slug (path)
graphOverviewTemplate "./templates/graph-overview.js" Template to use for the graph overview
graphOverviewPath "graph-overview" The route for the graph overview (e.g. in this case https://example.com/graph-overview)
linkifyHashtags false Set to true if you want text such as #Test to be automatically converted into a page and link.
hideDoubleBrackets false Set to true if you want [[Page]] to show up as Page without the double brackets
mdxOtherwiseConfigured false Used to workaround a bug in gatsby-plugin-mdx (see ChristopherBiscardi/gatsby-mdx#354). Set to true if you have already configured mdx
generateRSS false Enable this to generate an RSS feed from all notes with syndicate: true in the frontmatter. If you want to test this locally you will need to do gatsby build and then gatsby develop.
rssPath "/brainrss.xml" Adjust this to set the path of the generated RSS feed xml file
rssTitle "gatsby-theme-brain generated rss feed" Adjust this to set the title of the generated RSS feed
generateBrainMap false Set to true to generate a map for external subscribing
brainBaseUrl "" Configure the base url for the gatsby-theme-brain section of your site. Used by the brain map subscribers to generate links.
brainMapPath "static/brainmap.json" Set the path on your site where the brainmap json file will be generated
mappedExternalBrains {} Set to an object mapping from a name that will be used in the links (e.g. [[name/somepage]]), to the url for the external brainmap
timerReloadDelay 0 Change to something greater than 0 to enable automatic reloading of the map. This is useful when subscribed to other sites to regenerate those references. Value is in milliseconds, so 6000000 would regenerate your site every 10 minutes.

gatsby-theme-brain's People

Contributors

aengusmcmillin avatar alexdunne avatar benrobertsonio avatar dschapman avatar juancaicedo avatar mxstbr avatar tangdrew avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

gatsby-theme-brain's Issues

Querying notes in nested subfolders

Currently, the plugin requires that all the brain notes be stored in a flat top-level folder.
I'm wondering if it would be possible to query notes that are stored in multiple subfolders?

For example, I want to be able to query notes stored in ./content/notes/ and .content/books/ and pass them both into the plugin.

Would it be possible to have the notesDirectory option in gatsby.config accept a string of locations?

Support org-mode files

Hello! I really like this theme and its cousin andy. Thank you for making these available.

While I was exploring this theme (and gatsby) with org-mode files (through org-roam) I encountered the following:

"gatsby-plugin-mdx" threw an error while running the onCreateNode lifecycle:

unknown: Unexpected token (13:0)

  11 |   )
  12 | }
> 13 | #+end_src
     | ^
  14 | content/hello.org: unknown: Unexpected token (13:0)

  11 |   )
  12 | }
> 13 | #+end_src

I believe this is known limitation as the theme only support markdown files. I attempted to use https://orga.js.org/docs/generate-static-website-with-gatsby, however that does not yield the desired results as the notes are not pre-processed by the theme (I believe here).

Is this use-case known to you and do you know if this is possible?

GraphQL issue

Hey Aengus,

I really love the idea you have here.

I'm running into the following error when I launch the gatsby develop server

There was an error in your GraphQL query:

Cannot query field "inboundReferencePreviews" on type "BrainNote".

If you don't expect "inboundReferencePreviews" to exist on the type "BrainNote" it is most likely a typo.
However, if you expect "inboundReferencePreviews" to exist there are a couple of solutions to common problems:

- If you added a new data source and/or changed something inside gatsby-node.js/gatsby-config.js, please try a restart of your development server
- The field might be accessible in another subfield, please try your query in GraphiQL and use the GraphiQL explorer to see which fields you can query and what shape they have
- You want to optionally use your field "inboundReferencePreviews" and right now it is not used anywhere. Therefore Gatsby can't infer the type and add it to the GraphQL schema. A quick fix is to add at least one entry with that field ("dummy content")

It is recommended to explicitly type your GraphQL schema if you want to use optional fields. This way you don't have to add the mentioned "dummy content". Visit our docs to learn how you can define the schema for "BrainNote":
https://www.gatsbyjs.org/docs/schema-customization/#creating-type-definitions

File: /Users/nicholastorba/Documents/GitHub/hello-world/node_modules/@aengusm/gatsby-theme-brain/src/templates/brain.js

I installed the gatsby-theme-brain into the hello-world project given by gatsby (https://github.com/gatsbyjs/gatsby-starter-hello-world).

Do you know how I can resolve this?

Support Multiple Templates for Different Types of Notes

Brief Abstract

I would like to be able to render brain notes differently based on the type of note that I am taking.
Some types of notes would include: books, code snippets, sketchnotes, etc.

Proposed Implementation

I think adding a templateType or noteType on the Brian node schema and render whatever the node type is into its corresponding template. We could set the default as brain and the default template would be brain.js so that we wouldn't break anyones builds.

We could add template to the markdown frontmatter as a way of determining which template the file should be rendered as.

We will want to check that the templateType is found inside of the templates folder, this will likely require shadowing from the user.

If the user has not defined a template for their custom templateType we could print a warning that a template was not found and render the brain template as a default.

Enable 'Copy for Roam' behavior

Right now although you can copy notes out of Roam, you can't necessarily copy them back in or copy in notes from other sites because it automatically includes the link syntax and other markdown additions. It would be good to have a 'Copy Raw' or 'Copy for Roam' button to grab the raw original content of the markdown file, which should be totally compatible to paste into Roam or into your own Brain.

Probably the best way to do this would be to store the original markdown content in the BrainNote type.

As part of this task there should probably also be a component exported for copying this markdown content to the clipboard.

emacs temp file causes a crash

Background

  • I use spacemacs for tending my garden
    • It creates an autosave file for anything you are currently editing, like
      garden/.#empathizing-with-your-users.mdx
    • This file is added and then removed
    • I don't completely understand how this happens, and whether it's a configurable feature or not ๐Ÿ˜…

Problem

  • When I change a file in my content directory, my gatsby build breaks and I get the following error
    Error: ENOENT: no such file or directory, open 'garden/.#empathizing-with-your-users.mdx'
    
    - get-markdown-notes.js:23
      [personal-blog]/[@aengusm]/gatsby-theme-brain/src/get-markdown-notes.js:23:24
    
    - Array.map
    
    - get-markdown-notes.js:17 module.exports
      [personal-blog]/[@aengusm]/gatsby-theme-brain/src/get-markdown-notes.js:17:6
    

What's in previewHtml?

Hi Aengus! ๐Ÿ˜€

I'm going through and setting up this plugin and am a little confused about the shape of the inboundReferencePreviews on each note.

Looking at your example for how to render references, I see a property coming in that's previewHtml.

What ends up being included in previewHtml? In some of your pages, I see that it can carry quite a lot of content, like in https://aengusmcmillin.com/brain/books.

What content ends up being included in a preview?

I can draft up something to add to the docs about it ๐Ÿ‘

Graph Overview

I've replicated Roam's Graph Overview for my own site and wondered if it was something you'd be interested in adding to the gatsby-theme-brain project or if it's something best left in user-land.

Implementation is here if you're interested.

gatsby-theme-brain-graph-overview

Access childMdx frontmatter

@MaggieAppleton and I are integrating gatsby-theme-brain into her site (github link). Maggie currently uses frontmatter to annotate her posts with metadata:

https://github.com/MaggieAppleton/maggieappleton.com/blob/d0a805dedaae58a5282a3b5c9d8a0e05bef9bb83/src/templates/noteTemplate.js#L127-L132

We want to access these same fields through a brain note object. We thought that these fields should live here:

brainNote(slug: { eq: $slug }) {
  childMdx {
        body
        frontmatter {
          title
          date(formatString: "MMMM DD, YYYY")
          slug
          topics
        }
      }
}

But they are turning up null.

How can we access frontmatter of the mdx post?

Error in build

Background

  • I cloned this repo from the master branch onto my machine
  • I ran npm link in that directory to setup a symlink
  • I ran npm link @aengusm/gatsby-theme-brain in my gatsby project to run using my local verion
  • I ran gatsby develop

What happens

  • This error is thrown by the build
    ERROR
    
    UNHANDLED REJECTION expr is not a function
    
    
    
      TypeError: expr is not a function
    
      - source-nodes.js:57
        /Users/juan/code/personal/gatsby-theme-brain/src/source-nodes.js:57:21
      - interpreter.js:650 Interpreter.exec
        [gatsby-theme-brain]/[xstate]/lib/interpreter.js:650:24
    

Querying notes in multiple/nested subfolders

Currently, the plugin requires that all the brain notes be stored in a flat top-level folder.
I'm wondering if it would be possible to query notes that are stored in multiple subfolders?

For example, I want to be able to query notes stored in ./content/notes/ and ./content/books/ and pass them both into the plugin.

Would it be possible to have the notesDirectory option in gatsby.config accept a string of locations?

Allow for displaying links without brackets

In Roam, you can toggle visibility of the brackets for those style of links. It would be good to have the same thing here as an option.

There will likely just be a pluginOption to do this, and it should be a pretty simple change to the link insertion logic.

outboundReferences could be slugs instead of actual matches

Can we have slugs in the outboundReferences like we have for inboundReferences? This would help in fetching content from the outbound links with a few changes to the page query.

I could do this by adding

if(note.outboundReferences) {
  note.outboundReferences = note.outboundReferences.map(ob => nameToSlugMap[ob.toLowerCase()]||ob)
}

before creating the brainNote createNode(brainNoteNode).

But it feels hacky.

Fixing Graph Overview

Window not defined error while running gatsby build.
The following code should fix it after un-commenting the GraphOverview files:

--- gatsby-node.js ---
exports.onCreateWebpackConfig = ({ stage, loaders, actions }) => {
if (stage === "build-html") {
actions.setWebpackConfig({
module: {
rules: [
{
test: /react-cytoscapejs/,
use: loaders.null(),
},
],
},
})
}
}

--- GraphOverview.js ---
...
return (
typeof window !== "undefined"
&&

<CytoscapeComponent.
...

Let me know if this works for you. I can add a pull request to fix this.

Thanks for the theme! (:

content.matchAll(...) is not a function

I get this error on Netlify:

5:18:07 PM: error "@aengusm/gatsby-theme-brain" threw an error while running the sourceNodes lifecycle:
5:18:07 PM: content.matchAll(...) is not a function or its return value is not iterable
5:18:07 PM: 
5:18:07 PM:   TypeError: content.matchAll(...) is not a function or its return value is not   iterable

My netlify set up is relatively simple.. it just runs gatsby build and looks at the public/ directory.

When I run gatsby build locally. everything works fine.

heres a link to my site

Do you have any suggestions?

Allow for multiple instances of the Brain that can reference and automatically link to each other

This is a bit of a longer term idea, but eventually it could be useful to explicitly support allowing this theme to be instantiated multiple times on a single site reading from different folders and writing to different urls. This may be possible now but it is untested.

And to pull the real power out of that, if possible the different instances should be able to optionally know about each other and automatically provide links to the same note on the other instances if it exists.

So for example, you could have a site shared between Bill and Jane with the following structure:

- content
-- bill_brain
--- books.md
--- movies.md
-- jane_brain
--- books.md

And when the books page is rendered for Bill it could include a link to Jane's books page, and vice versa, but nothing would change for Bill's movies page. I don't know exactly how this could be used, but it feels like there are continuations of this idea that could make it an incredibly powerful shared library of information.

Idea from here.

Optional support for #Tag auto linking

Roam automatically generates pages and links when a hashtag is used. This theme still doesn't support that.

Personally though, I don't always love this behavior. I like to be able to say things like #1, or mention a twitter hashtag, and not have it automatically create a page. I am thinking I will add this behavior but default it to off and allow it to be enabled with a plugin option.

Doesn't work with gatsby develop

As I am not a programmer and I have a bad code, I ask this question in case it is possible to solve it.

Gatsby CLI version: 3.8.0
Gatsby version: 2.32.13

I install the gatsby theme with the official instructions:

gatsby new my-new-brain https://github.com/scttcper/gatsby-casper
cd my-new-brain
gatsby develop

And I get this:

ERROR #10126  CONFIG

/path/my-new-brain/gatsby-config cannot export a function.

A gatsby-config exported as a Function can only be used as a theme and not run
directly.
If you are trying to run a theme directly, use the theme in an example site or
starter instead and run that site to test.
If you are in the root gatsby-config.js for your site, change the export to be
an object and not a function as functions
are not supported in the root gatsby-config.

can it be solved?

Thanks for everything.

Support spaces in note file names

I see that related questions about how note titles are used have been asked in #4, #8 and aravindballa/gatsby-theme-andy#10.

The behaviour I was expecting is that I can write [[Example Note]] to reference a note with no YAML called 'Example Note.md'. Instead, it looks like I have to have 'example-note.md' with title: "Example Note" in the YAML.

Firstly, is it right that spaces in note file names are not currently supported in gatsby-theme-brain? Secondly, is there a way to support the behaviour I expected?

Allow custom component imports into MDX notes

A lot of my notes have custom React component imports at the top.

These components are usually kept in the same folder as the note (but given the current top-folder-level system for gatsby-theme-brain, I'll likely to move them into a single /note-components location).

When I try to run them with gatsby-theme-brain I get a caching error. Eg.

Generating development JavaScript bundle failed

Can't resolve './Tools.js' in '/Users/maggie/Documents/GitHub/maggieappleton.com/.cache/caches/gatsby-plugin-mdx/mdx-scopes-dir'

File: .cache/caches/gatsby-plugin-mdx/mdx-scopes-dir/87e93eac8b8fe4b4034bd8543157f22a.js

Cleaned the cache 99 times and it has yet to work ๐Ÿ˜…

Popped it onto a branch here: https://github.com/MaggieAppleton/maggieappleton.com/tree/bidirectional-custom-components-error

The note I was testing it out with is apps.mdx, and trying to import components from Tools.js

All the other component-less notes work fine. Seems to only be an issue with component imports.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.