@@ -53,72 +53,8 @@ defmodule Tableau.PostExtension do
53
53
54
54
use Tableau.Extension , key: :posts , type: :pre_build , priority: 100
55
55
56
- { :ok , config } =
57
- Tableau.PostExtension.Config . new ( Map . new ( Application . compile_env ( :tableau , Tableau.PostExtension , % { } ) ) )
58
-
59
- @ config config
60
-
61
56
def run ( token ) do
62
- :global . trans (
63
- { :create_posts_module , make_ref ( ) } ,
64
- fn ->
65
- Module . create (
66
- Tableau.PostExtension.Posts ,
67
- quote do
68
- use NimblePublisher ,
69
- build: __MODULE__ . Post ,
70
- from: "#{ unquote ( @ config . dir ) } /**/*.md" ,
71
- as: :posts ,
72
- parser: Tableau.PostExtension.Posts.Post ,
73
- html_converter: Tableau.PostExtension.Posts.HTMLConverter
74
-
75
- def posts ( _opts \\ [ ] ) do
76
- @ posts
77
- |> Enum . sort_by ( & & 1 . date , { :desc , DateTime } )
78
- |> then ( fn posts ->
79
- if unquote ( @ config . future ) do
80
- posts
81
- else
82
- Enum . reject ( posts , & DateTime . after? ( & 1 . date , DateTime . utc_now ( ) ) )
83
- end
84
- end )
85
- end
86
- end ,
87
- Macro.Env . location ( __ENV__ )
88
- )
89
-
90
- for { mod , _ , _ } <- :code . all_available ( ) ,
91
- mod = Module . concat ( [ to_string ( mod ) ] ) ,
92
- { :ok , :page } == Tableau.Graph.Node . type ( mod ) ,
93
- mod . __tableau_opts__ ( ) [ :__tableau_post_extension__ ] do
94
- :code . purge ( mod )
95
- :code . delete ( mod )
96
- end
97
-
98
- posts =
99
- for post <- apply ( Tableau.PostExtension.Posts , :posts , [ ] ) do
100
- { :module , _module , _binary , _term } =
101
- [ :"#{ System . unique_integer ( ) } " ]
102
- |> Module . concat ( )
103
- |> Module . create (
104
- quote do
105
- use Tableau.Page , unquote ( Macro . escape ( Keyword . new ( post ) ) )
106
-
107
- @ external_resource unquote ( post . file )
108
- def template ( _assigns ) do
109
- unquote ( post . body )
110
- end
111
- end ,
112
- Macro.Env . location ( __ENV__ )
113
- )
114
-
115
- post
116
- end
117
-
118
- { :ok , Map . put ( token , :posts , posts ) }
119
- end ,
120
- [ Node . self ( ) ] ,
121
- :infinity
122
- )
57
+ token = put_in ( token . posts , Tableau.PostExtension.Posts . posts ( ) )
58
+ { :ok , token }
123
59
end
124
60
end
0 commit comments