<commit_before>// Actions
import { UPDATE_PAGE_META } from 'actions'

// Content
import navItems from 'content/nav-items'

let pageMeta = {}

const changePageMetaOnLinkMatch = (item, path) => {
	let re = new RegExp('(' + item.to + ')'),
		linkMatch = re.test(path)

	if (linkMatch) {
		pageMeta = {
			title: item.name,
			description: item.description
		}
	}

	return linkMatch
}

function getMetaFromNavItems(items, path) {
	return items.some((item) => {
		if (item.subitems) {
			return getMetaFromNavItems(item.subitems, path)
		}

		return changePageMetaOnLinkMatch(item, path)
	})
}

function updatePageMeta(path) {
	if (!getMetaFromNavItems(navItems, path)) {
		pageMeta = {
			title: '404',
			description: '404 - File Not Found'
		}
	}

	if (typeof window === 'undefined') {
		return
	}

	let { title, description } = pageMeta
	title && (document.title = title + ' – Tabletop Helper')
	description && (document.querySelector('meta[name=description]').content = description)
}

function updateScrollPosition() {
	if (typeof window !== 'undefined') {
		window && window.scroll(0, 0)
	}
}

export default (state = {}, action) => {
	let { type, path, payload } = action

	switch (type) {
	case UPDATE_PAGE_META:
		updatePageMeta(path)

		return {
			...state,
			title: pageMeta.title,
			description: pageMeta.description
		}

	case '@@router/UPDATE_PATH':
		let currentPath = payload.path,
			previousPath = state.currentPath,
			pathChanged = currentPath !== previousPath

		updatePageMeta(path)
		pathChanged && updateScrollPosition()

		return {
			...state,
			currentPath,
			previousPath,
			pathChanged,
			title: pageMeta.title,
			description: pageMeta.description
		}

	default:
		return state<commit_msg>Fixed all named paths showing up as 404<commit_after>// Actions
import { UPDATE_PAGE_META } from 'actions'

// Content
import navItems from 'content/nav-items'

let pageMeta = {}

const changePageMetaOnLinkMatch = (item, path) => {
	console.log(item.to, path);
	let re = new RegExp('(' + item.to + ')'),
		linkMatch = re.test(path)

	if (linkMatch) {
		pageMeta = {
			title: item.name,
			description: item.description
		}
	}

	return linkMatch
}

function getMetaFromNavItems(items, path) {
	return items.some((item) => {
		if (item.subitems) {
			return getMetaFromNavItems(item.subitems, path)
		}

		return changePageMetaOnLinkMatch(item, path)
	})
}

function updatePageMeta(path) {
	console.log(getMetaFromNavItems(navItems, path));
	if (!getMetaFromNavItems(navItems, path)) {
		pageMeta = {
			title: '404',
			description: '404 - File Not Found'
		}
	}

	if (typeof window === 'undefined') {
		return
	}

	let { title, description } = pageMeta
	title && (document.title = title + ' – Tabletop Helper')
	description && (document.querySelector('meta[name=description]').content = description)
}

function updateScrollPosition() {
	if (typeof window !== 'undefined') {
		window && window.scroll(0, 0)
	}
}

export default (state = {}, action) => {
	let { type, path, payload } = action

	switch (type) {
	case UPDATE_PAGE_META:
		updatePageMeta(path)

		return {
			...state,
			title: pageMeta.title,
			description: pageMeta.description
		}

	case '@@router/UPDATE_PATH':
		let currentPath = payload.path,
			previousPath = state.currentPath,
			pathChanged = currentPath !== previousPath

		updatePageMeta(currentPath)
		pathChanged && updateScrollPosition()

		return {
			...state,
			currentPath,
			previousPath,
			pathChanged,
			title: pageMeta.title,
			description: pageMeta.description
		}

	default:
		return state
{'fraction_non_alphanumeric': 0.131852684846781, 'fraction_numerical': 0.005341579983131853, 'mean_word_length': 3.9075862068965517, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3208437', 'n_tokens_mistral': 1295, 'n_tokens_neox': 1149, 'n_words': 272}