Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Sanity Exhibition Nansen
Manage
Activity
Members
Plan
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
uib-ub
Spesialsamlingene
Utstillinger
Sanity Exhibition Nansen
Commits
399384a5
Commit
399384a5
authored
3 years ago
by
Tarje.Lavik
Browse files
Options
Downloads
Patches
Plain Diff
Use numbers for footnote link
parent
a86e8a3e
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
web/components/PT/PortableTextBlock.js
+15
-9
15 additions, 9 deletions
web/components/PT/PortableTextBlock.js
web/lib/utils/getFootnotesNumberArray.js
+21
-0
21 additions, 0 deletions
web/lib/utils/getFootnotesNumberArray.js
web/lib/utils/index.js
+1
-0
1 addition, 0 deletions
web/lib/utils/index.js
with
37 additions
and
9 deletions
web/components/PT/PortableTextBlock.js
+
15
−
9
View file @
399384a5
...
...
@@ -26,6 +26,7 @@ import {
}
from
'
../Sections
'
import
ActorInsert
from
'
./Inserts/ActorInsert
'
import
PlaceInsert
from
'
./Inserts/PlaceInsert
'
import
{
getFootnotesNumberArray
}
from
'
../../lib/utils
'
const
BlockContent
=
require
(
'
@sanity/block-content-to-react
'
)
...
...
@@ -45,6 +46,8 @@ export default function PortableTextBlock(props) {
...
rest
}
=
props
const
footnoteNumbers
=
getFootnotesNumberArray
(
props
.
blocks
)
const
getFontSize
=
(
level
)
=>
{
switch
(
level
)
{
case
'
h2
'
:
...
...
@@ -115,20 +118,23 @@ export default function PortableTextBlock(props) {
<
Link
href
=
{
href
}
>
{
text
}
<
/Link
>
)
},
footnote
:
({
children
,
markKey
})
=>
(
<
span
>
{
children
}
<
sup
>
{
/*
footnote
:
({
children
,
markKey
})
=>
{
console
.
log
(
markKey
)
return
(
<
span
>
{
children
}
<
sup
>
{
/*
https://codesandbox.io/s/how-to-render-footnotes-in-portable-text-in-react-iupur?file=/src/index.js:254-650
If you want numbers here, you can reuse the reduce function from Footnotes.js
to e.g. an object with markKey as keys and the index as values.
{[markKey]: index}.
*/
}
<
a
href
=
{
`#
${
markKey
}
`
}
>*<
/a
>
<
/sup
>
<
/span
>
),
<
a
href
=
{
`#
${
markKey
}
`
}
>
{
footnoteNumbers
[
markKey
]}
<
/a
>
<
/sup
>
<
/span
>
)
},
},
types
:
{
code
:
(
props
)
=>
(
...
...
This diff is collapsed.
Click to expand it.
web/lib/utils/getFootnotesNumberArray.js
0 → 100644
+
21
−
0
View file @
399384a5
/**
* getFootnoteNumberArray
* return object
*/
export
const
getFootnotesNumberArray
=
(
blocks
)
=>
{
return
(
blocks
// filter out everything that's not a text block
.
filter
(({
_type
})
=>
_type
===
'
block
'
)
// make an array of the mark definitions of those blocks
.
reduce
((
acc
,
curr
)
=>
{
return
[...
acc
,
...
curr
.
markDefs
]
},
[])
// find all the footnote mark definitions
.
filter
(({
_type
})
=>
_type
===
'
footnote
'
)
// reduce to object with mark as key and index as value
.
reduce
(
function
(
acc
,
curr
,
index
)
{
return
{
...
acc
,
[
curr
.
_key
]:
index
+
1
}
},
{})
)
}
This diff is collapsed.
Click to expand it.
web/lib/utils/index.js
+
1
−
0
View file @
399384a5
export
*
from
'
./capitalize
'
export
*
from
'
./convertQuotationMarks
'
export
*
from
'
./getFootnotesNumberArray
'
export
*
from
'
./getOpenGraphImages
'
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment