Open abnerlee opened 5 years ago
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
"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.
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.
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?
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.
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.
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
Delete image file not fix ? so sad 😔
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...
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.
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