typora-issues icon indicating copy to clipboard operation
typora-issues copied to clipboard

[Summary] better image / resources reference management

Open abnerlee opened this issue 6 years ago • 11 comments

  • [ ] Rename assert folder when file renamed (#2084)
  • [ ] Delete image file when image reference is delete in Typora (#2194)
  • [x] Upload Image (#2175)
  • [ ] Prompt for image name upon pasting from clipboard (#2436)
  • [ ] Rename image when insert / paste (#4636)
  • [ ] Empty Alt (#4660)
  • [ ] Syntax Preferences (#4674)

Currently the issue is that Typora cannot know if target images are used by other files/users or not, so, it is unclear if it is safe to delete/move images.

Also, relates #985 for url

abnerlee avatar Feb 19 '19 08:02 abnerlee

Typora isn't just an editor, it shapes user's habits. From my using experience, images copied/pasted is put under the asset directory. If I want to reference it in a document, this document is likely to be associated with the category, i.e., the parent directory of asset. So I think, If there's no pictures referenced, maybe the pictures can be removed! But wait, it's dangerous. Maybe we rename the pictures, meanwhile they're not referenced. They can'be be removed immediately, but there may be another solution to notify users, 'hey, you have some pictures not referenced, will you review and clean them?' Hope we can support it. @abnerlee

hitzhangjie avatar Mar 06 '19 04:03 hitzhangjie

"Typora cannot know if target images are used by other files/users" , for #2084 , you can only rename the file in ${filename}.assert to ensure safe.

dulm avatar Mar 08 '19 08:03 dulm

Since a lot of people are probably syncing their files with a limited storage, preventing from bloat is also a big concern like safety. Not being able to know if target images are used by other files/users makes this problem harder.

I think best option is to provide a prompt after deleting a section of image -multiple prompts, if multiple deletion. Afterwards user can tick images and click delete button or delete all button. Such a setup seems to contradict with Typora's simplistic design. Yet no one really wants to deal with randomly named image files that fills up entire cloud storage.

kirbiyik avatar Apr 26 '19 23:04 kirbiyik

I know there's an option for choosing whether you want %20 or spaces in image referenes… but why not just make everything %20 and then appear as if it's spaces?

lakinchris avatar Aug 11 '19 18:08 lakinchris

Currently the issue is that Typora cannot know if target images are used by other files/users or not, so, it is unclear if it is safe to delete/move images.

We can add a button likes "delete all unreferenced images (in .asset)", to let users decide whether it's safe to delete those unused images.

Levi-Hope avatar Oct 27 '19 07:10 Levi-Hope

Is there a place where we can keep track of changes regarding this? I simply can't use Typora unless this is fixed, I got way too many files and images. Seeing that this thread is a year old I am wondering if this is 'on the menu' anytime soon.

ScribbleGhost avatar Jan 05 '20 17:01 ScribbleGhost

A simple bash script to delete unused figures (.assets/.png) for a given folder's md files.

#!/bin/bash


removeEmptyFigureDir()
{
    figureDir=${1}

    if [[ -d ${figureDir} ]] && \
       [[ ! "$(ls -A ${figureDir})" ]]; then

        printf "Remove empty ${figureDir}.\n"
        rm -r ${figureDir}
    fi
}


removeUnusedFigureForFile()
{
    fileName="${1}"
    baseName=`python -c "print('.'.join('${fileName}'.\
        split('.')[:-1]))"`

    figureDir="${baseName}.assets"

    removeEmptyFigureDir ${figureDir}

    if [[ -d ${figureDir} ]]; then
        cd ${figureDir}
    else
        exit
    fi

    for figureFile in *.*; do
        if grep -Fq "${figureFile}" ../"${fileName}"; then
            printf "${figureDir}/${figureFile} is in used.\n"

        else
            printf "${figureDir}/${figureFile} is not in used. "

            rm ${figureFile}
            printf "Deleted.\n"
        fi
    done

    cd ~-
    removeEmptyFigureDir ${figureDir}
}


removeUnusedFigureForDir()
{
    dirName="${1}"
    cd ${dirName}

    for figureDir in *.assets; do

        removeEmptyFigureDir ${figureDir}

        if [[ -d ${figureDir} ]]; then
            cd ${figureDir}
        else
            continue
        fi

        for figureFile in *.*; do
            figureFileInUsed="False"

            for mdFile in ../*.md; do
                if grep -Fq "${figureFile}" "${mdFile}"; then
                    printf "${figureDir}/${figureFile} is in used.\n"
                    figureFileInUsed="True"
                    break
                fi
            done

            if [[ $figureFileInUsed == "False" ]]; then
                printf "${figureDir}/${figureFile} is not in used. "

                rm ${figureFile}

                printf "Deleted.\n"
            fi

        done

        cd ~-

        removeEmptyFigureDir $figureDir
    done

    cd ~-
}


if [[ $# -ge 1 ]]; then
    if [[ -f ${1} ]]; then
        removeUnusedFigureForFile ${1}

    elif [[ -d ${1} ]]; then
        removeUnusedFigureForDir ${1}

    else
        printf "${1} is not found as a directory or file.\n"
    fi

else
    echo "Please input dir/file name."
fi


Liguobing00 avatar Apr 02 '20 02:04 Liguobing00

Delete image file not fix ? so sad 😔

ghost avatar Oct 01 '21 08:10 ghost

I still don't see a way to delete ununsed picture. When I'm writing documents, I frequently update images. And since I habe a lot of images, I don't name them.

My picture folder gets pretty bloated...

tih2010 avatar Aug 07 '23 09:08 tih2010

I still don't see a way to delete ununsed picture. When I'm writing documents, I frequently update images. And since I habe a lot of images, I don't name them.

My picture folder get's pretty bloated...

I switched to Obsidian because of this, and because of this. To be fair Obsidian does all of this and a ton more for free. I don't see a reason to use Typora at all anymore.

ScribbleGhost avatar Aug 07 '23 12:08 ScribbleGhost

Image

I'm trying to create and use my own image upload feature — not for actual uploading, but mainly for renaming files and specifying a folder to "upload" them to. However, I'm encountering a "validation failed". I suspect this happens because the file path is not a remote location like HTTPS. I was wondering what you think — if it wasn't strictly limited to remote locations, users could use the feature more flexibly, such as just for renaming files. what do you thing about that?

shinnyeonki avatar May 29 '25 06:05 shinnyeonki

Image I'm trying to create and use my own image upload feature — not for actual uploading, but mainly for renaming files and specifying a folder to "upload" them to. However, I'm encountering a "validation failed". I suspect this happens because the file path is not a remote location like HTTPS. I was wondering what you think — if it wasn't strictly limited to remote locations, users could use the feature more flexibly, such as just for renaming files. what do you thing about that?

I'm encountering the same issue. +1 for removing the restrictions

mobilephone724 avatar Sep 05 '25 09:09 mobilephone724