Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
Gatsby Theme Onegeo
Manage
Activity
Members
Plan
Redmine
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OneGeo Suite
Libs
Gatsby Theme Onegeo
Commits
08cc84d2
Commit
08cc84d2
authored
2 years ago
by
Julien MARGAIL
Browse files
Options
Downloads
Patches
Plain Diff
fix Link internal check
parent
c8fe920c
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/components/core/Link.tsx
+23
-14
23 additions, 14 deletions
src/components/core/Link.tsx
with
23 additions
and
14 deletions
src/components/core/Link.tsx
+
23
−
14
View file @
08cc84d2
// From https://www.gatsbyjs.com/docs/reference/built-in-components/gatsby-link/
// From https://www.gatsbyjs.com/docs/reference/built-in-components/gatsby-link/
import
React
from
"
react
"
import
React
from
"
react
"
import
{
Link
as
GatsbyLink
}
from
"
gatsby
"
import
{
graphql
,
useStaticQuery
,
Link
as
GatsbyLink
}
from
"
gatsby
"
interface
Props
{
interface
Props
{
children
?:
React
.
ReactNode
children
?:
React
.
ReactNode
to
:
string
to
:
string
activeClassName
?:
string
activeClassName
?:
string
partiallyActive
?:
any
partiallyActive
?:
any
onClick
?:
any
onClick
?:
any
className
?:
any
className
?:
any
}
}
...
@@ -25,34 +24,44 @@ const Link = ({
...
@@ -25,34 +24,44 @@ const Link = ({
className
,
className
,
...
other
...
other
}:
Props
)
=>
{
}:
Props
)
=>
{
// Si commence par http
// Basé sur les données de l'API GraphQL = liste des pages
// Si contient
const
data
=
useStaticQuery
(
graphql
`
// geoportal | geonetwork | metabase | ...
query appPages {
allSitePage {
// Basé sur les données de l'api grapgql = liste des pages ?
nodes {
path
}
}
}
`
)
// Tailor the following test to your environment.
// /^https?:\/\//
// This example assumes that any internal link (intended for Gatsby)
// Si "to" n'est pas dans la liste des pages, c'est un lien externe
// will start with exactly one slash, and that anything else is external.
// ignore le "/" à la fin du 'path' et de 'to'
const
internal
=
/^
\/(?!\/)
/
.
test
(
to
)
const
internal
=
data
.
allSitePage
.
nodes
.
find
(
({
path
})
=>
path
.
replace
(
/
\/
+$/
,
""
)
===
to
.
replace
(
/
\/
+$/
,
""
)
)
// Use Gatsby Link for internal links, and <a> for others
// Use Gatsby Link for internal links, and <a> for others
if
(
internal
)
{
if
(
internal
)
{
// console.log("Internal", to)
return
(
return
(
<
GatsbyLink
<
GatsbyLink
to
=
{
to
}
to
=
{
to
}
activeClassName
=
{
activeClassName
}
activeClassName
=
{
activeClassName
}
partiallyActive
=
{
partiallyActive
}
partiallyActive
=
{
partiallyActive
}
onClick
=
{
onClick
}
onClick
=
{
onClick
}
className
=
{
className
}
className
=
{
className
}
{
...
other
}
{
...
other
}
>
>
{
children
}
{
children
}
</
GatsbyLink
>
</
GatsbyLink
>
)
)
}
}
// console.log("External", to)
return
(
return
(
<
a
href
=
{
to
}
{
...
other
}
onClick
=
{
onClick
}
className
=
{
className
}
>
<
a
href
=
{
to
}
{
...
other
}
onClick
=
{
onClick
}
className
=
{
className
}
>
{
children
}
{
children
}
</
a
>
</
a
>
)
)
...
...
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