Skip to content
This repository has been archived by the owner on Oct 25, 2022. It is now read-only.

Commit

Permalink
Make footnotes node types configurable and extendible
Browse files Browse the repository at this point in the history
  • Loading branch information
avoinea committed Aug 6, 2020
1 parent f049530 commit 3f1cf82
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/blocks/Footnote/FootnotesBlockView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {
getBlocksFieldname,
getBlocksLayoutFieldname,
} from '@plone/volto/helpers';
import { FOOTNOTE } from 'volto-slate/constants';
import './less/public.less';
import { settings } from '~/config';

const getBlocks = (properties) => {
const blocksFieldName = getBlocksFieldname(properties);
Expand All @@ -18,10 +18,11 @@ const getBlocks = (properties) => {
const FootnotesBlockView = (props) => {
const { data, properties } = props;
const { title } = data;
const { footnotes } = settings;

// console.log(properties);
const blocks = getBlocks(properties);
const footnotes = [];
const notes = [];
// TODO: slice the blocks according to existing footnote listing blocks.
// A footnote listing block should reset the counter of the footnotes above it
// If so, then it should only include the footnotes between the last footnotes listing block and this block
Expand All @@ -31,18 +32,18 @@ const FootnotesBlockView = (props) => {
if (!value) return;

Array.from(Node.elements(value[0])).forEach(([node]) => {
if (node.type === FOOTNOTE) {
footnotes.push(node);
if (footnotes.includes(node.type)) {
notes.push(node);
}
});
});

return (
<div className="footnotes-listing-block">
<h3>{title}</h3>
{footnotes && (
{notes && (
<ol>
{footnotes.map(({ data }) => {
{notes.map(({ data }) => {
const { uid, footnote } = data;
return (
<li key={uid} id={`footnote-${uid}`}>
Expand Down
3 changes: 3 additions & 0 deletions src/blocks/Footnote/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import codeSVG from '@plone/volto/icons/code.svg';

import FootnotesBlockView from './FootnotesBlockView';
import FootnotesBlockEdit from './FootnotesBlockEdit';
import { FOOTNOTE } from 'volto-slate/constants';

export default function install(config) {
config.blocks.blocksConfig.slateFootnotes = {
Expand All @@ -20,5 +21,7 @@ export default function install(config) {
view: [],
},
};

config.settings.footnotes = [...(config.settings.footnotes || []), FOOTNOTE];
return config;
}

0 comments on commit 3f1cf82

Please sign in to comment.