Skip to content

Commit

Permalink
Merge pull request #14 from kalwalt/dev
Browse files Browse the repository at this point in the history
Dev switcher feature
  • Loading branch information
kalwalt committed Mar 17, 2019
2 parents f4a562e + f465f18 commit 729cb35
Show file tree
Hide file tree
Showing 32 changed files with 201 additions and 91 deletions.
2 changes: 1 addition & 1 deletion gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ exports.createPages = ({ actions, graphql }) => {
slug
}
frontmatter {
id
date
path
tags
templateKey
nameSlug
lang
title
}
Expand Down
12 changes: 5 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "gatsby-starter-contentful-i18n",
"name": "gatsby-starter-i18n-bulma",
"private": true,
"description": "Gatsby example site using the Contentful source plugin and i18n",
"version": "2.0.0",
"author": "Paul McCrodden <paul.mccrodden@x-team.com> (paulmccrodden.com)",
"description": "Gatsby example site using i18n and bulma for CSS",
"version": "0.1.5",
"author": "Walter Perdan <info@kalwaltart.it> (www.kalwaltart.it)",
"dependencies": {
"@fortawesome/fontawesome-svg-core": "^1.2.15",
"@fortawesome/free-brands-svg-icons": "^5.7.2",
Expand Down Expand Up @@ -52,9 +52,7 @@
],
"license": "MIT",
"main": "n/a",
"resolutions": {
"contentful": "6.1.0"
},
"resolutions": "",
"scripts": {
"develop": "gatsby develop",
"build": "gatsby build",
Expand Down
6 changes: 3 additions & 3 deletions src/components/Flags/En.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ const En = (props) => {
<Icon viewBox="0 0 640 480" {...props}>
<defs>
<clipPath id="a">
<path fill-opacity=".7" d="M-85.3 0h682.6v512H-85.3z"/>
<path fillOpacity=".7" d="M-85.3 0h682.6v512H-85.3z"/>
</clipPath>
</defs>
<g clip-path="url(#a)" transform="translate(80) scale(.94)">
<g stroke-width="1pt">
<g clipPath="url(#a)" transform="translate(80) scale(.94)">
<g strokeWidth="1pt">
<path fill="#012169" d="M-256 0H768v512H-256z"/>
<path fill="#fff" d="M-256 0v57.2L653.5 512H768v-57.2L-141.5 0H-256zM768 0v57.2L-141.5 512H-256v-57.2L653.5 0H768z"/>
<path fill="#fff" d="M170.7 0v512h170.6V0H170.7zM-256 170.7v170.6H768V170.7H-256z"/>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Flags/It.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Icon from 'react-icon-base';
const It = (props) => {
return (
<Icon viewBox="0 0 640 480" {...props}>
<g fill-rule="evenodd" stroke-width="1pt">
<g fillRule="evenodd" strokeWidth="1pt">
<path fill="#fff" d="M0 0h640v480H0z"/>
<path fill="#009246" d="M0 0h213.3v480H0z"/>
<path fill="#ce2b37" d="M426.7 0H640v480H426.7z"/>
Expand Down
11 changes: 7 additions & 4 deletions src/components/Footer.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import React from 'react'
import { Link } from 'gatsby'
import select from '../components/utils'
import menuTree from '../data/menuTree'

import logo from '../img/logo.svg'

const Footer = class extends React.Component {
render() {
const props = this.props;
const sel = select(props.langKey);
return (
<footer className="footer has-background-black has-text-white-ter">
<div className="content has-text-centered">
Expand All @@ -22,8 +25,8 @@ const Footer = class extends React.Component {
<section className="menu">
<ul className="menu-list">
<li><Link to={props.langKey} className="navbar-item">Home</Link></li>
<li><Link className="navbar-item" to={props.langKey + "/about"}>About</Link></li>
<li><Link className="navbar-item" to={props.langKey + "/artworks"}>
<li><Link className="navbar-item" to={props.langKey + "/" + menuTree.about[sel] +"/"}>About</Link></li>
<li><Link className="navbar-item" to={props.langKey + "/" + menuTree.artworks[sel] +"/"}>
Artworks
</Link>
</li>
Expand All @@ -42,12 +45,12 @@ const Footer = class extends React.Component {
<section>
<ul className="menu-list">
<li>
<Link className="navbar-item" to={props.langKey + "/blog"}>
<Link className="navbar-item" to={props.langKey + "/" + menuTree.blog[sel] +"/"}>
Latest Stories
</Link>
</li>
<li>
<Link className="navbar-item" to={props.langKey + "/contact"}>
<Link className="navbar-item" to={props.langKey + "/" + menuTree.contact[sel] +"/"}>
Contact
</Link>
</li>
Expand Down
23 changes: 13 additions & 10 deletions src/components/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import Link from 'gatsby-link'
import logo from '../img/logo.svg'
import { FaHome, FaQuestion, FaImage, FaPenAlt, FaAmericanSignLanguageInterpreting } from 'react-icons/fa';
import SelectLanguage from './SelectLanguage';
import { FormattedMessage } from 'react-intl';
import menuTree from '../data/menuTree'
import select from '../components/utils'

const Header = class extends React.Component {

Expand Down Expand Up @@ -31,7 +34,7 @@ const Header = class extends React.Component {
render() {

const props = this.props;

const sel = select(props.langKey);
return (

<header>
Expand All @@ -54,19 +57,19 @@ const Header = class extends React.Component {
<div id="navMenu" className="navbar-menu">
<div className="navbar-start has-text-centered">
<Link className="navbar-item" to={props.langKey}>
<FaHome /> Home
<FaHome /> <FormattedMessage id="home" />
</Link>
<Link className="navbar-item" to={props.langKey + "/about/"}>
<FaQuestion /> About
<Link className="navbar-item" to={props.langKey + "/" + menuTree.about[sel] +"/"}>
<FaQuestion /> <FormattedMessage id="about" />
</Link>
<Link className="navbar-item" to={props.langKey + "/artworks/"}>
<FaImage /> Artworks
<Link className="navbar-item" to={props.langKey + "/" + menuTree.artworks[sel] +"/"}>
<FaImage /> <FormattedMessage id="artworks" />
</Link>
<Link className="navbar-item" to={props.langKey + "/blog/"}>
<FaPenAlt /> Blog
<Link className="navbar-item" to={props.langKey + "/" + menuTree.blog[sel] +"/"}>
<FaPenAlt /> <FormattedMessage id="blog" />
</Link>
<Link className="navbar-item" to={props.langKey + "/contact/"}>
<FaAmericanSignLanguageInterpreting /> Contact
<Link className="navbar-item" to={props.langKey + "/" + menuTree.contact[sel] +"/"}>
<FaAmericanSignLanguageInterpreting /> <FormattedMessage id="contact" />
</Link>
</div>
</div>
Expand Down
48 changes: 44 additions & 4 deletions src/components/Layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import PropTypes from 'prop-types'
import Header from '../components/Header'
import Footer from '../components/Footer'
import Helmet from 'react-helmet'
import { getCurrentLangKey, getLangs, getUrlForLang } from 'ptz-i18n';
import { getCurrentLangKey, getLangs, getUrlForLang, getSlugAndLang } from 'ptz-i18n';
import { IntlProvider, addLocaleData } from 'react-intl';
import { rhythm } from "../utils/typography"
import 'intl';
Expand All @@ -17,6 +17,43 @@ import 'intl/locale-data/jsonp/it';
import './all.sass'
import 'font-awesome/css/font-awesome.css'

import articleId from '../data/articleTree'
import menuTree from '../data/menuTree'


const getIdUrl = (id, langKey) => {
if(id){
var res;
switch (langKey) {
//we get the name of the page according the id
case 'en':
res = articleId[id][0];
break;
case 'it':
res = articleId[id][1];
break;
default: return null;
}
return res;
}
};

const startPath = (langKey, langsMenu, basename, _url) => {
const lengthLangKey = langKey.length;
var indx;
indx = _url.indexOf(basename);
const basePath = _url.slice(lengthLangKey + 2, indx);
return basePath;
};


const setLangsMenu = ( langsMenu, id, basePath) => {
if(id){
langsMenu[0].link = `/en/${basePath}` + getIdUrl(id, 'en');
langsMenu[1].link = `/it/${basePath}` + getIdUrl(id, 'it');
}
};

// add concatenated locale data
addLocaleData([...en, ...it]);

Expand All @@ -30,9 +67,12 @@ class TemplateWrapper extends Component {
const { langs, defaultLangKey } = data.site.siteMetadata.languages;
this.langKey = getCurrentLangKey(langs, defaultLangKey, url);
this.homeLink = `/${this.langKey}/`;
console.log("language is: ");
console.log(this.langKey);
this.langsMenu = getLangs(langs, this.langKey, getUrlForLang(this.homeLink, url));
const id_article = data.markdownRemark.frontmatter.id;
const basename = getIdUrl(id_article, this.langKey);
var basePath = startPath(this.langKey, this.langsMenu, basename, url);
//finally here we set the desired url...
setLangsMenu( this.langsMenu, id_article, basePath);

// get the appropriate message file based on langKey
// at the moment this assumes that langKey will provide us
Expand All @@ -53,7 +93,7 @@ class TemplateWrapper extends Component {
{ name: 'keywords', content: 'sample, something' },
]}
/>
<Header langKey={this.langKey} langs={this.langsMenu} />
<Header langKey={this.langKey} langs={this.langsMenu} menu={this.menuTree} />
<div>
{this.children}
</div>
Expand Down
16 changes: 16 additions & 0 deletions src/components/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const select = (langKey) => {
var res;
switch(langKey){
case('en'):
res = 0;
break;
case('it'):
res = 1;
break;
default:
res = null;
}
return res;
};

export default select;
9 changes: 9 additions & 0 deletions src/data/articleTree.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
'1': ['/', '/'],
'2': ['about','presentazione'],
'3': ['contact','contatto'],
'4': ['artworks','opere'],
'5': ['artworks-page-test','pagina-opere-test'],
'6': ['2019-02-01-my-first-gatsby-blog-post','2019-02-01-mio-primo-blog-post-gatsby'],
'7': ['2019-03-11-news-from-art-planet', '2019-03-11-notizie-dal-pianeta-arte'],
};
6 changes: 6 additions & 0 deletions src/data/menuTree.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
'about': ['about', 'presentazione'],
'artworks': ['artworks', 'opere'],
'blog': ['blog', 'blog'],
'contact': ['contact', 'contatto']
};
9 changes: 7 additions & 2 deletions src/data/messages/en.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
module.exports = {
'selectLanguage': 'Select your language'
};
'selectLanguage': 'Select your language',
'home': 'Home',
'about': 'About',
'artworks': 'Artworks',
'blog': 'Blog',
'contact': 'Contacts',
};
7 changes: 6 additions & 1 deletion src/data/messages/it.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
module.exports = {
'selectLanguage': 'Seleziona la lingua'
'selectLanguage': 'Seleziona la lingua',
'home': 'Casa',
'about': 'A proposito',
'artworks': 'Opere',
'blog': 'Blog',
'contact': 'Contatti',
};
2 changes: 1 addition & 1 deletion src/pages/about.en.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
id: 02
title: "About me"
description: "Something about me"
nameSlug: page-about-en
templateKey: home
lang: en
date: "05-03-2019"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
id: 05
title: "Artworks page english"
description: "qualche contenuto"
templateKey: artworks
nameSlug: pagina-artrwork-en
tags:
- art
lang: it
Expand Down
2 changes: 1 addition & 1 deletion src/pages/artworks/index.en.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
id: 04
title: "Artworks start page english"
description: "The root of the artwork page"
templateKey: artworks
nameSlug: artwork-page-en
tags:
- art
lang: en
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
id: 06
templateKey: blog-post
title: My first gatsby blog post.
title: Il mio primo post con Gatsby.
date: 2019-02-01T22:31:28.375Z
description: Il mio primo blog con Gatsby...
lang: it
Expand Down
3 changes: 2 additions & 1 deletion src/pages/blog/2019-02-01-my-first-gatsby-blog-post.en.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
id: 06
templateKey: blog-post
title: Il mio primo blog post con Gatsby.
title: My first gatsby blog post.
date: 2019-02-01T22:31:28.375Z
description: My first gatsby blog post really...
lang: en
Expand Down
1 change: 1 addition & 0 deletions src/pages/blog/2019-03-11-news-from-art-planet.en.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
id: 07
templateKey: blog-post
title: News from the art planet.
date: 2019-03-11
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
id: 07
templateKey: blog-post
title: News dal mondo dell'arte.
date: 2019-03-11
Expand Down
4 changes: 2 additions & 2 deletions src/pages/contact.en.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
id: 03
title: "Contact page"
description: "Page to send an e-mail"
nameSlug: page-contact-en
templateKey: contacts
tags:
- web
nameLabel: "Your name"
lang: it
lang: en
date: "08-03-2019"
path: /en/contact
slug: /en/contact
Expand Down
6 changes: 3 additions & 3 deletions src/pages/contact.it.md → src/pages/contatto.it.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
---
id: 03
title: "Pagina di contatto"
description: "Pagina per contattarmi"
nameSlug: pagina-contact-it
templateKey: contacts
tags:
- web
nameLabel: "Il tuo nome"
lang: it
date: "08-03-2019"
path: /it/contact
slug: /it/contact
path: /it/contatto
slug: /it/contatto
---

In questa pagina di contatto puoi inviare una e-mail.
2 changes: 1 addition & 1 deletion src/pages/index.en.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
id: 01
title: "English home page"
description: "qualche contenuto"
nameSlug: pagina-home-en
templateKey: home
tags:
- web
Expand Down
2 changes: 1 addition & 1 deletion src/pages/index.it.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
id: 01
title: "Pagina home italiano"
description: "qualche contenuto"
nameSlug: pagina-home-it
templateKey: home
tags:
- web
Expand Down
Loading

0 comments on commit 729cb35

Please sign in to comment.