Action

雛型(新規ドラフト作成)

Posted by sorashima, Last update about 2 years ago

UPDATES

about 2 years ago

日付はDate Pickerで選択できるようにした。
カスタムテンプレートは、
[[DofW]] : 曜日
[[Y]] : 年(4桁)
[[m]] : 月(2桁)
[[d]] : 日 (2桁)
[[F]] : 年-月-日

show all updates...

about 2 years ago

日付はDate Pickerで選択できるようにした。
カスタムテンプレートは、
[[DofW]] : 曜日
[[Y]] : 年(4桁)
[[m]] : 月(2桁)
[[d]] : 日 (2桁)
[[F]] : 年-月-日

about 2 years ago

Templatesフォルダに.mustacheファイル等の.txt以外のファイルが含まれていてもエラーにならないように修正。

about 2 years ago

Templatesフォルダに.mustacheファイル等の.txtが含まれていてもエラーにならないように修正。

about 2 years ago

Add blog page URL

日本語の曜日も挿入でき、Drafrs freeでも利用できるテンプレートアクション。
実行すると新しいドラフトが作成される。

Template actions that can also insert Japanese days of the week and are also available in Drafrs free.

https://sorashima.hatenablog.com/entry/DraftsTemplateJapanese

Steps

  • script

    const f = () => {
    
      const fmC = FileManager.createCloud()
      const ls = fmC.listContents("Library/Templates/")
      if (ls.length == 0) {
        alert("テンプレートが一つも保存されていません。")
        return false
      }
      const p = Prompt.create()
      p.title = "テンプレートを選択"
      ls.forEach(fp => {
        const mS = /^Library\/Templates\/(.+)\.txt$/.exec(fp)
        if (mS !== null) p.addButton(mS[1], fp)
      })
      p.addDatePicker("pickedDate", "日付", new Date(), {mode: "date"})
      if (!p.show()) return false
      const content = fmC.readString(p.buttonPressed)
      const d = new Draft()
      const pd = p.fieldValues["pickedDate"]
      d.setTemplateTag("DofW", ('月火水木金土日').substr(strftime(pd, '%u')-1, 1))
      d.setTemplateTag("F", strftime(pd, '%F'))
      d.setTemplateTag("Y", strftime(pd, '%Y'))
      d.setTemplateTag("m", strftime(pd, '%m'))
      d.setTemplateTag("d", strftime(pd, '%d'))
      d.content = d.processTemplate(content)
      d.update()
    	// load new draft
      editor.load(d)
      editor.activate()
    	
      // look for <|> to set cursor location
      const loc = d.content.search("<|>")
      if (loc != -1) {
    		editor.setText(editor.getText().replace("<|>", ""))
    		editor.setSelectedRange(loc, 0)
    	}
    
      return true
    }
    
    if (!f()) context.cancel()
    

Options

  • After Success Default
    Notification Info
    Log Level Info
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.