Skip to content

Commit

Permalink
removed model/head.js
Browse files Browse the repository at this point in the history
  • Loading branch information
modestysn committed Sep 29, 2019
1 parent 080d7d9 commit f4a1bb1
Show file tree
Hide file tree
Showing 12 changed files with 64 additions and 53 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react2html",
"version": "0.2.0",
"version": "0.2.1",
"description": "react2html - component based web site development starter kit",
"private": false,
"homepage": "https://github.com/modesty/react2html",
Expand Down
12 changes: 4 additions & 8 deletions src/scripts/components/Head.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
import React from 'react';

import processRelPath from '../model/head';

const Head = ({ title, description, styles, scripts, rel }) => {
const { touchHref, webMan, styleLinks, scriptLinks } = processRelPath(rel, styles, scripts);
const Head = ({ title, description, links, styles, scripts }) => {
return (
<head>
<meta charSet="utf-8" />
<title>{title}</title>
<meta name="description" content={description} />
<meta name="viewport" content="width=device-width, initial-scale=1" />

<link rel="manifest" href={webMan} />
<link rel="apple-touch-icon" href={touchHref} />
{Object.entries(links).map((entry, i) => <link key={i} rel={entry[0]} href={entry[1]} />)}
{styles.map( (s, i) => <link rel="stylesheet" href={s} key={i} /> )}
{scripts.map((s, i) => <script src={s} key={i} />)}

{styleLinks.map( (s, i) => <link rel="stylesheet" href={s} key={i} /> )}
{scriptLinks.map((s, i) => <script src={s} key={i} />)}
<meta name="theme-color" content="#fafafa" />
</head>
);
Expand Down
7 changes: 3 additions & 4 deletions src/scripts/components/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import Menu from './Menu';

import processRelPath from '../model/header';

const Header = ({ title, rel }) => {
let dataModel = processRelPath(rel);
let {homeLink, bannerLink} = dataModel;
const Header = ({ title, rel = "" }) => {
const { homeLink, bannerLink, socials } = processRelPath(rel);

return (
<header className='header'>
Expand All @@ -28,7 +27,7 @@ const Header = ({ title, rel }) => {
<div className="col-md-3 hidden-sm hidden-xs">
<div className="soc-area">
<div className="icons-social">
{dataModel.socials.map( s => <a href={s.href} className={s.id} key={s.id}></a>)}
{socials.map( s => <a href={s.href} className={s.id} key={s.id}></a>)}
</div>
</div>
</div>
Expand Down
4 changes: 1 addition & 3 deletions src/scripts/components/Main.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
"use strict";

import React from 'react';

let Main = (props) =>
const Main = (props) =>
<main className=''>
{props.children}
</main>;
Expand Down
4 changes: 2 additions & 2 deletions src/scripts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import Header from './components/Header';
import Main from './components/Main';
import Footer from './components/Footer';

const Root = ({title,description,scripts,styles,rel, gaKey}) => {
const Root = ({title,description,links,scripts,styles,rel, gaKey}) => {
return (
<html className="no-js" lang="en">
<Head title={title} description={description} scripts={scripts} styles={styles} rel={rel} />
<Head title={title} description={description} links={links} scripts={scripts} styles={styles} rel={rel} />
<body data-track={gaKey} className='container'>
<Header title={title} />
<Main>
Expand Down
15 changes: 0 additions & 15 deletions src/scripts/model/head.js

This file was deleted.

13 changes: 5 additions & 8 deletions src/scripts/model/header.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import path from 'path';

const HeaderModel = {
homeLink: {name: "Home", href: "./", img: "img/logo.png"},
bannerLink: {name: "Banner Ad", href: "", img: "http://placehold.it/420x60"},
Expand All @@ -11,12 +13,7 @@ const HeaderModel = {
]
};

export default function processRelPath(rel) {
let relPath = rel ? rel : "";

let homeLink = HeaderModel.homeLink, bannerLink = HeaderModel.bannerLink;

homeLink = {...homeLink, href: relPath + homeLink.href, img: relPath + homeLink.img};

return {...HeaderModel, homeLink: homeLink};
export default function processRelPath(rel = "") {
const { homeLink:preHomeLink } = HeaderModel;
return {...HeaderModel, homeLink: {...preHomeLink, href: path.join(rel, preHomeLink.href), img: path.join(rel, preHomeLink.img)}};
}
6 changes: 3 additions & 3 deletions src/scripts/pages/about.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import Header from '../components/Header';
import Main from '../components/Main';
import Footer from '../components/Footer';

const About = ({title,description,scripts,styles,rel, gaKey}) => {
const About = ({title,description,links, scripts,styles,rel, gaKey}) => {
return (
<html className="no-js" lang="en">
<Head title={title} description={description} scripts={scripts} styles={styles} rel={rel} />
<Head title={title} description={description} links={links} scripts={scripts} styles={styles} rel={rel} />
<body data-track={gaKey} className='container'>
<Header title={title} />
<Header title={title} rel={rel} />
<Main>
<h1>About React2Html</h1>
<p>More details can be found at <a href="https://github.com/modesty/react2html"> GitHub </a></p>
Expand Down
6 changes: 3 additions & 3 deletions src/scripts/pages/contact.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import Header from '../components/Header';
import Main from '../components/Main';
import Footer from '../components/Footer';

const Contact = ({title,description,scripts,styles,rel, gaKey}) => {
const Contact = ({title,description,links,scripts,styles,rel,gaKey}) => {
return (
<html className="no-js" lang="en">
<Head title={title} description={description} scripts={scripts} styles={styles} rel={rel} />
<Head title={title} description={description} links={links} scripts={scripts} styles={styles} rel={rel} />
<body data-track={gaKey} className='container'>
<Header title={title} />
<Header title={title} rel={rel} />
<Main>
<h1>Contact Me</h1>
<p>email the author: <a href="mailto:[email protected]?subject=About%20CoeProject%20Article">[email protected]</a></p>
Expand Down
14 changes: 10 additions & 4 deletions src/scripts/props/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import path from 'path';
import glob from 'glob';

const pkg = require('../../../package.json');
import Conf from '../../../tool/base.config';
import glob from 'glob';

export default {
title: `Welcome to ${pkg.name} v${pkg.version}`,
description: pkg.description,
scripts: glob.sync('**/*.js', { cwd: Conf.target.js_path }),
styles: glob.sync('**/*.css', { cwd: Conf.target.css_path }),
rel: './',
links: {
"site.webmanifest": "site.webmanifest",
"apple-touch-icon": "apple-touch-icon.png"
},
scripts: glob.sync('**/*.js', { cwd: Conf.target.js_path }).map(s => path.join("js", s)),
styles: glob.sync('**/*.css', { cwd: Conf.target.css_path }).map( s => path.join("css", s)),
rel: '',
gaKey: Conf.TRACK_ID
}
17 changes: 16 additions & 1 deletion src/scripts/props/pages/about.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
import path from 'path';
import indexProps from '../index';

export default { ...indexProps, rel: '../', title: "About", description: "About Modesty Zhang"};
const baseDir = path.resolve(__dirname, "..");
const rel = path.relative(__dirname, baseDir);

const links = Object.keys(indexProps.links).reduce((ret, key) => {
ret[key] = path.join(rel, indexProps.links[key]);
return ret;
}, {});

const scripts = indexProps.scripts.map(s => path.join(rel, s));
const styles = indexProps.styles.map(s => path.join(rel, s));

export default {
...indexProps, rel, links, styles, scripts,
title: "About", description: "About Modesty Zhang"
};
17 changes: 16 additions & 1 deletion src/scripts/props/pages/contact.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
import path from 'path';
import indexProps from '../index';

export default { ...indexProps, rel: '../', title: "Contact", description: "Contact Modesty Zhang"};
const baseDir = path.resolve(__dirname, "..");
const rel = path.relative(__dirname, baseDir);

const links = Object.keys(indexProps.links).reduce((ret, key) => {
ret[key] = path.join(rel, indexProps.links[key]);
return ret;
}, {});

const scripts = indexProps.scripts.map(s => path.join(rel, s));
const styles = indexProps.styles.map(s => path.join(rel, s));

export default {
...indexProps, rel, links, styles, scripts,
title: "Contact", description: "Contact Modesty Zhang"
};

0 comments on commit f4a1bb1

Please sign in to comment.