import React, { Component } from 'react'; import { Link } from 'react-router-dom'; import Icon from 'react-fontawesome'; import { Row } from './skeleton'; import { slugify } from './util'; class ListLink extends Component { render () { let icon = null; if (this.props.icon) { icon = } return (
  • { icon } { this.props.name }
  • ); } } class NavList extends Component { constructor(props) { super(props); this.state = { pageLinks: null, } } componentDidMount() { fetch('/site.json') .then(resp => resp.json()) .then(blob => { let links = []; for (let page of blob.pages) { let slug = page.slug; if (!slug) { slug = slugify(page.title); } if (page.parent == null) { let href = "/" + slug; links.push(); } } this.setState({pageLinks: links}); }); } render() { return (
      { this.state.pageLinks }
    ); } } class TagNav extends Component { constructor (props) { super(props); // TODO: fetch this number from config // Number of top tags to display this.numTop = 5; this.state = { topTags: [], } } fetchTopTags () { fetch('/site.json') .then(resp => resp.json()) .then(blob => { let counts = new Map(); // Count up the tags blob.posts.forEach(post => { post.tags.forEach(tag => { let count = counts.get(tag); if (count === undefined) { count = 0; } counts.set(tag, count + 1); }); }); // Sort the tags let tags = [...counts.entries()]; tags.sort(function(t1, t2) { let tag1 = t1[0]; let tag2 = t2[0]; let count1 = t1[1]; let count2 = t2[1] let diff = count2 - count1; if (diff !== 0) { return diff } else { // We have a tie, sort by the strings return tag1.localeCompare(tag2); } }); // Get just the tag names tags = tags.map(t => t[0]); // Get top N tags = tags.slice(0, this.numTop); this.setState({topTags: tags}); }); } componentDidMount() { this.fetchTopTags(); } render() { let tags = ""; if (this.state.topTags.length > 0) { tags = (
    Top Tags
      {this.state.topTags.map(tag => ( ))}
    ); } return ( { tags } ); } } const HistoryNav = (props) => { let left = ""; let right = ""; if (props.prev) { left = ( newer posts ); } if (props.next) { right = ( older posts ); } return ( { left } { right } ) } export { ListLink, NavList, TagNav, HistoryNav };