<commit_before>export default function (context) {
    var document = context.document
    var root = document.fileURL().path().stringByDeletingLastPathComponent()
    var currentPage = document.currentPage()
    document.pages().forEach(page => {
        document.setCurrentPage(page)
        exportPage(document, root, page)
    })
    document.setCurrentPage(currentPage)
}

function exportPage(document, root, page) {
    var pageName = page.name()
    var index = pageName.indexOf(" | ")
    var name = index == -1 ? pageName : pageName.substring(0, index)
    var pagePath = index == -1 ? "" : pageName.substring(index + 3)
    var path = pagePath[0] == "~" ? pagePath : root + "/" + pagePath

    console.log("导出: " + name + "(" + path + ")")

    page.children().forEach(layer => {
        if (layer == page)
            return

        var options = layer.exportOptions()
        var formats = options.exportFormats()
        if (formats.count() <= 0)
            return

        formats.forEach(format => {
            var name = layer.name()
            if (format.name() != null) {
                if (format.namingScheme()) {
                    name = format.name() + name
                } else {
                    name = name + format.name()
                }
            }
            name = name + "." + format.fileFormat()

            console.log(" - " + name)

            // 导出
            exportFormat(document, layer, options, format, path + "/" + name)
        })
    })
}

function exportFormat(document, layer, options, format, file) {
    var slice = MSExportRequest.new()
    slice.rect = layer.absoluteRect().rect()
    slice.scale = format.scale()
    slice.format = format.fileFormat()<commit_msg>修复默认路径处理<commit_after>export default function (context) {
    var document = context.document
    var root = document.fileURL().path().stringByDeletingLastPathComponent()
    var currentPage = document.currentPage()
    document.pages().forEach(page => {
        document.setCurrentPage(page)
        exportPage(document, root, page)
    })
    document.setCurrentPage(currentPage)
}

function exportPage(document, root, page) {
    var pageName = page.name()
    var index = pageName.indexOf(" | ")
    var name = index == -1 ? pageName : pageName.substring(0, index)
    var pagePath = index == -1 ? "" : pageName.substring(index + 3)
    var path = pagePath[0] == "~" ? pagePath : root + (pagePath == "" ? "" : "/" + pagePath)

    console.log("导出: " + name + " (" + path + ")")

    page.children().forEach(layer => {
        if (layer == page)
            return

        var options = layer.exportOptions()
        var formats = options.exportFormats()
        if (formats.count() <= 0)
            return

        formats.forEach(format => {
            var name = layer.name()
            if (format.name() != null) {
                if (format.namingScheme()) {
                    name = format.name() + name
                } else {
                    name = name + format.name()
                }
            }
            name = name + "." + format.fileFormat()

            console.log(" - 图片：" + name)

            // 导出
            exportFormat(document, layer, options, format, path + "/" + name)
        })
    })
}

function exportFormat(document, layer, options, format, file) {
    var slice = MSExportRequest.new()
    slice.rect = layer.absoluteRect().rect()
    slice.scale = format.scale()
    slice.format = format.fileFormat()
{'fraction_non_alphanumeric': 0.14031563845050216, 'fraction_numerical': 0.003443328550932568, 'mean_word_length': 2.047202797202797, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '2187167', 'n_tokens_mistral': 1003, 'n_tokens_neox': 985, 'n_words': 219}