<commit_before>import { attempt, flatten, isError } from 'lodash';
import { Map } from 'immutable';
import fuzzy from 'fuzzy';
import { resolveFormat } from 'Formats/formats';
import { selectIntegration } from 'Reducers/integrations';
import {
  selectListMethod,
  selectEntrySlug,
  selectEntryPath,
  selectAllowNewEntries,
  selectAllowDeletion,
  selectFolderEntryExtension,
  selectIdentifier,
  selectInferedField,
} from 'Reducers/collections';
import { createEntry } from 'ValueObjects/Entry';
import { sanitizeSlug } from 'Lib/urlHelper';
import { getBackend } from 'Lib/registry';
import { Cursor, CURSOR_COMPATIBILITY_SYMBOL } from 'netlify-cms-lib-util';
import { EDITORIAL_WORKFLOW, status } from 'Constants/publishModes';

class LocalStorageAuthStore {
  storageKey = 'netlify-cms-user';

  retrieve() {
    const data = window.localStorage.getItem(this.storageKey);
    return data && JSON.parse(data);
  }

  store(userData) {
    window.localStorage.setItem(this.storageKey, JSON.stringify(userData));
  }

  logout() {
    window.localStorage.removeItem(this.storageKey);
  }
}

const slugFormatter = (collection, entryData, slugConfig) => {
  const template = collection.get('slug') || '{{slug}}';
  const date = new Date();

  const identifier = entryData.get(selectIdentifier(collection));
  if (!identifier) {
    throw new Error('Collection must have a field name that is a valid entry identifier');
  }

  const slug = template
    .replace(/\{\{([^}]+)\}\}/g, (_, field) => {
      switch (field) {
        case 'year':
          return date.getFullYear();
        case 'month':
          return `0${date.getMonth() + 1}`.slice(-2);
        case 'day':
          return `0${date.getDate()}`.slice(-2);
        case 'hour':
          return `0${date.getHours()}`.slice(-2);
        case 'minute':
          return `0${date.getMinutes()}`.slice(-2);
        case 'second':
          return `0${date.getSeconds()}`.slice(-2);
        case 'slug':
          return identifier.trim();
        default:
          return entryData.get(field, '').trim();
      }
    })
    // Convert slug to lower-case
    .toLocaleLowerCase()

    // Replace periods with dashes.
    .replace(/[.]/g, '-');

  return sanitizeSlug(slug, slugConfig);
};

const commitMessageTemplates = Map({
  create: 'Create {{collection}} “{{slug}}”',
  update: 'Update {{collection}} “{{slug}}”',
  delete: 'Delete {{collection}} “{{slug}}”',
  uploadMedia: 'Upload “{{path}}”',
  deleteMedia: 'Delete “{{path}}”',
});

const commitMessageFormatter = (type, config, { slug, path, collection }) => {
  const templates = commitMessageTemplates.merge(
    config.getIn(['backend', 'commit_messages'], Map()),
  );
  const messageTemplate = templates.get(type);
  return messageTemplate.replace(/\{\{([^}]+)\}\}/g, (_, variable) => {
    switch (variable) {
      case 'slug':
        return slug;
      case 'path':
        return path;
      case 'collection':
        return collection.get('label');
      default:
        console.warn(`Ignoring unknown variable “${variable}” in commit message template.`);
        return '';<commit_msg>Remove single quotes before creating slug (#1781)<commit_after>import { attempt, flatten, isError } from 'lodash';
import { Map } from 'immutable';
import fuzzy from 'fuzzy';
import { resolveFormat } from 'Formats/formats';
import { selectIntegration } from 'Reducers/integrations';
import {
  selectListMethod,
  selectEntrySlug,
  selectEntryPath,
  selectAllowNewEntries,
  selectAllowDeletion,
  selectFolderEntryExtension,
  selectIdentifier,
  selectInferedField,
} from 'Reducers/collections';
import { createEntry } from 'ValueObjects/Entry';
import { sanitizeSlug } from 'Lib/urlHelper';
import { getBackend } from 'Lib/registry';
import { Cursor, CURSOR_COMPATIBILITY_SYMBOL } from 'netlify-cms-lib-util';
import { EDITORIAL_WORKFLOW, status } from 'Constants/publishModes';

class LocalStorageAuthStore {
  storageKey = 'netlify-cms-user';

  retrieve() {
    const data = window.localStorage.getItem(this.storageKey);
    return data && JSON.parse(data);
  }

  store(userData) {
    window.localStorage.setItem(this.storageKey, JSON.stringify(userData));
  }

  logout() {
    window.localStorage.removeItem(this.storageKey);
  }
}

const slugFormatter = (collection, entryData, slugConfig) => {
  const template = collection.get('slug') || '{{slug}}';
  const date = new Date();

  const identifier = entryData.get(selectIdentifier(collection));
  if (!identifier) {
    throw new Error('Collection must have a field name that is a valid entry identifier');
  }

  const slug = template
    .replace(/\{\{([^}]+)\}\}/g, (_, field) => {
      switch (field) {
        case 'year':
          return date.getFullYear();
        case 'month':
          return `0${date.getMonth() + 1}`.slice(-2);
        case 'day':
          return `0${date.getDate()}`.slice(-2);
        case 'hour':
          return `0${date.getHours()}`.slice(-2);
        case 'minute':
          return `0${date.getMinutes()}`.slice(-2);
        case 'second':
          return `0${date.getSeconds()}`.slice(-2);
        case 'slug':
          return identifier.trim();
        default:
          return entryData.get(field, '').trim();
      }
    })
    // Convert slug to lower-case
    .toLocaleLowerCase()

    // Remove single quotes.
    .replace(/[']/g, '')

    // Replace periods with dashes.
    .replace(/[.]/g, '-');

  return sanitizeSlug(slug, slugConfig);
};

const commitMessageTemplates = Map({
  create: 'Create {{collection}} “{{slug}}”',
  update: 'Update {{collection}} “{{slug}}”',
  delete: 'Delete {{collection}} “{{slug}}”',
  uploadMedia: 'Upload “{{path}}”',
  deleteMedia: 'Delete “{{path}}”',
});

const commitMessageFormatter = (type, config, { slug, path, collection }) => {
  const templates = commitMessageTemplates.merge(
    config.getIn(['backend', 'commit_messages'], Map()),
  );
  const messageTemplate = templates.get(type);
  return messageTemplate.replace(/\{\{([^}]+)\}\}/g, (_, variable) => {
    switch (variable) {
      case 'slug':
        return slug;
      case 'path':
        return path;
      case 'collection':
        return collection.get('label');
      default:
        console.warn(`Ignoring unknown variable “${variable}” in commit message template.`);
        return '';
{'fraction_non_alphanumeric': 0.16159545956172158, 'fraction_numerical': 0.004099006779126596, 'mean_word_length': 3.3994452149791954, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '7646570', 'n_tokens_mistral': 1944, 'n_tokens_neox': 1917, 'n_words': 450}