dword-design/nuxt-route-meta

not working code

rucebee opened this issue · 7 comments

In my setup value.value not exists

  let data = {}
  if (Component.script?.content) {
    const ast = babel.parseSync(Component.script.content, { filename })
    traverse(ast, {
      ExportDefaultDeclaration: path => {
        data =
          path.node.declaration.properties
          |> filter('key.name')
          |> keyBy('key.name')
          |> pick(options.properties)
          //--|> mapValues('value.value')
          //++
          |> mapValues('value.properties')
      },
    })
  }
  if ('meta' in data) {
    Object.assign(data, data.meta)
    delete data.meta
    //++
    data = 
        data
        |> keyBy('key.name')
        |> mapValues('value.value')
  }

works for meta with no inner hierarchy

@rucebee Do you have the code of the meta definition you are parsing?

unfortunately, i have not found any meta definition example, so, that is how i define meta in my pages/one.vue.

<script>
    import {buildMetaTags} from '../utils/seo'

    export default {
        components: {},

        meta: {
            authRequest: true,
            xxx: 'yyy',
        },
        ...
    }
</script>

that is my quick fix to the module's dist

if ((_Component$script = Component.script) === null || _Component$script === void 0 ? void 0 : _Component$script.content) {
   const ast = babel.parseSync(Component.script.content, {
     filename
   });
   (0, _traverse.default)(ast, {
     ExportDefaultDeclaration: path => {
       var _ref, _ref2, _ref3, _path$node$declaratio;

       //data = (_ref = (_ref2 = (_ref3 = (_path$node$declaratio = path.node.declaration.properties, (0, _filter.default)('key.name')(_path$node$declaratio)), (0, _keyBy.default)('key.name')(_ref3)), (0, _pick.default)(options.properties)(_ref2)), (0, _mapValues.default)('value.value')(_ref));
       data = (_ref = (_ref2 = (_ref3 = (_path$node$declaratio = path.node.declaration.properties, (0, _filter.default)('key.name')(_path$node$declaratio)), (0, _keyBy.default)('key.name')(_ref3)), (0, _pick.default)(options.properties)(_ref2)), (0, _mapValues.default)('value.properties')(_ref));
     }
   });
 }

 if ('meta' in data) {
   Object.assign(data, data.meta);
   delete data.meta;
   var _ref;

   data = (_ref = (data, (0, _keyBy.default)('key.name')(data)), (0, _mapValues.default)('value.value')(_ref));
 }

thanks for nice module and your immediate reply))

@rucebee hmm that's strange. I think easiest would be if you could setup a minimal failing example repo and link it here. I tried to reproduce it with your page file and it worked.

ok, in few days i will upload it to git

i just found that the latest nuxt itself pushes page's Component.options.meta to route.meta[0] at runtime.
as route.meta is array i failed to read the value. i treated it as key-value map

but anyway it was nice experience to investigate your plugin))

@rucebee I think the meta injection only works for middlewares, but it's not in the routes object itself. At least I tried it again and the meta object is empty. But feel free to add an example repo.

but it's not in the routes object itself - yes that's true - metas are added at runtime

and they are accessible even at Vue this.$route.meta[0] - that's not true(( I made mistake

as i see your plugin is particularly needed at nuxt build time - you'd better to state this moment at plugin description and to be compliant with nuxt runtime array style, such as route.meta is array, route.meta[0] is page component.options.meta

But feel free to add an example repo - sure, i'm new to git publishing, so, it'll take some time)) sorry

@rucebee I explained the purpose of this module clearer in the readme. Also, I added an issue that tackles the structural inconsistency in #5. I guess we can close this issue for now, feel free to reopen it.