def git_permalink(content, git_content):
    '''
    Add git based permalink id to content metadata
    '''
    if not content.settings['GIT_GENERATE_PERMALINK']:
        return

    if not string_to_bool(content.metadata.get('git_permalink', 'yes')):
        # Disable for this content
        return

    if not git_content.is_committed():
        return

    permalink_hash = hashlib.sha1()
    update_hash_from_str(permalink_hash, git_content.get_oldest_commit())
    update_hash_from_str(permalink_hash, git_content.get_oldest_filename())
    git_permalink_id_raw = base64.urlsafe_b64encode(permalink_hash.digest())
    git_permalink_id = git_permalink_id_raw.decode("UTF-8")
    permalink_id_metadata_key = content.settings['PERMALINK_ID_METADATA_KEY']

    if permalink_id_metadata_key in content.metadata:
        content.metadata[permalink_id_metadata_key] = (
            ','.join((
                content.metadata[permalink_id_metadata_key], git_permalink_id))
        )
    else:
        content.metadata[permalink_id_metadata_key] = git_permalink_id
def git_permalink ( content , git_content ) : if not content . settings [ 'GIT_GENERATE_PERMALINK' ] : return if not string_to_bool ( content . metadata . get ( 'git_permalink' , 'yes' ) ) : return if not git_content . is_committed ( ) : return permalink_hash = hashlib . sha1 ( ) update_hash_from_str ( permalink_hash , git_content . get_oldest_commit ( ) ) update_hash_from_str ( permalink_hash , git_content . get_oldest_filename ( ) ) git_permalink_id_raw = base64 . urlsafe_b64encode ( permalink_hash . digest ( ) ) git_permalink_id = git_permalink_id_raw . decode ( "UTF-8" ) permalink_id_metadata_key = content . settings [ 'PERMALINK_ID_METADATA_KEY' ] if permalink_id_metadata_key in content . metadata : content . metadata [ permalink_id_metadata_key ] = ( ',' . join ( ( content . metadata [ permalink_id_metadata_key ] , git_permalink_id ) ) ) else : content . metadata [ permalink_id_metadata_key ] = git_permalink_id
Add git based permalink id to content metadata