from been.core import DirectorySource, source_registry

class MarkdownDirectory(DirectorySource):
    kind = 'markdown'
    def process_event(self, event):
        lines = event['content'].splitlines()
        event['title'] = lines[0]
        event['content'] = "\n".join(lines[1:])
        event['summary'] = event['content']
        return event
source_registry.add(MarkdownDirectory)

from been.core import DirectorySource, source_registry
import re
import unicodedata

def slugify(value):
    value = unicodedata.normalize('NFKD', unicode(value)).encode('ascii', 'ignore')
    value = unicode(re.sub('[^\w\s-]', '', value).strip().lower())
    return re.sub('[-\s]+', '-', value)

class MarkdownDirectory(DirectorySource):
    kind = 'markdown'
    def process_event(self, event):
        lines = event['content'].splitlines()
        event['title'] = lines[0]
        event['slug'] = slugify(event['title'])
        event['content'] = "\n".join(lines[1:])
        event['summary'] = event['content']
        return event
source_registry.add(MarkdownDirectory)

Add slug generation to Markdown source.
Add slug generation to Markdown source.

  from been.core import DirectorySource, source_registry
+ import re
+ import unicodedata
+ 
+ def slugify(value):
+     value = unicodedata.normalize('NFKD', unicode(value)).encode('ascii', 'ignore')
+     value = unicode(re.sub('[^\w\s-]', '', value).strip().lower())
+     return re.sub('[-\s]+', '-', value)
  
  class MarkdownDirectory(DirectorySource):
      kind = 'markdown'
      def process_event(self, event):
          lines = event['content'].splitlines()
          event['title'] = lines[0]
+         event['slug'] = slugify(event['title'])
          event['content'] = "\n".join(lines[1:])
          event['summary'] = event['content']
          return event
  source_registry.add(MarkdownDirectory)
  
Add slug generation to Markdown source.
## Code Before:
from been.core import DirectorySource, source_registry

class MarkdownDirectory(DirectorySource):
    kind = 'markdown'
    def process_event(self, event):
        lines = event['content'].splitlines()
        event['title'] = lines[0]
        event['content'] = "\n".join(lines[1:])
        event['summary'] = event['content']
        return event
source_registry.add(MarkdownDirectory)

## Instruction:
Add slug generation to Markdown source.
## Code After:
from been.core import DirectorySource, source_registry
import re
import unicodedata

def slugify(value):
    value = unicodedata.normalize('NFKD', unicode(value)).encode('ascii', 'ignore')
    value = unicode(re.sub('[^\w\s-]', '', value).strip().lower())
    return re.sub('[-\s]+', '-', value)

class MarkdownDirectory(DirectorySource):
    kind = 'markdown'
    def process_event(self, event):
        lines = event['content'].splitlines()
        event['title'] = lines[0]
        event['slug'] = slugify(event['title'])
        event['content'] = "\n".join(lines[1:])
        event['summary'] = event['content']
        return event
source_registry.add(MarkdownDirectory)
